Exemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();

            // C1XLBookがExcelブックを表すクラス
            C1XLBook book = new C1XLBook();

            // XLSheetがExcelのシートを表す
            XLSheet sheet = book.Sheets[0];

            // 1行目の1から3列目に値を設定する
            sheet[0, 0].Value = 1;
            sheet[0, 1].Value = 2;
            sheet[0, 2].Value = 3;

            // スタイルを設定する
            XLStyle style = new XLStyle(book);

            style.ForeColor = Colors.Blue;

            sheet[0, 1].Style = style;

            // 式を用いる
            // 1行目の1から3列のSUM(合計)を4列目に求める
            sheet[0, 3].Formula = "SUM(A1: C1)";

            // 画像を設定する
            WriteableBitmap img = new WriteableBitmap(new BitmapImage(new Uri("icon.png", UriKind.Relative)));

            sheet[1, 0].Value = img;


            // 保存する
            book.Save(@"C:\<ドキュメントフォルダのパス>\mybook.xls");
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            // step 1: create a new workbook
            C1XLBook book = new C1XLBook();

            // step 2: get the sheet that was created by default, give it a name
            XLSheet sheet = book.Sheets[0];

            sheet.Name = "Hello World";

            // step 3: create styles for odd and even values
            XLStyle styleOdd = new XLStyle(book);

            styleOdd.Font      = new Font("Tahoma", 9, FontStyle.Italic);
            styleOdd.ForeColor = Color.Blue;
            XLStyle styleEven = new XLStyle(book);

            styleEven.Font      = new Font("Tahoma", 9, FontStyle.Bold);
            styleEven.ForeColor = Color.Red;

            // step 3: write content and format into some cells
            for (int i = 0; i < 100; i++)
            {
                XLCell cell = sheet[i, 0];
                cell.Value = i + 1;
                cell.Style = ((i + 1) % 2 == 0)? styleEven: styleOdd;
            }

            // step 4: save the file
            string fileName = Application.StartupPath + @"\hello.xls";

            book.Save(fileName);
            System.Diagnostics.Process.Start(fileName);
        }
        private void btnStyles_Click(object sender, RoutedEventArgs e)
        {
            SaveBook(book =>
            {
                // get the sheet that was created by default, give it a name
                var sheet = book.Sheets[0];

                // create styles for odd and even values
                var styleOdd       = new XLStyle(book);
                styleOdd.Font      = new XLFont("Tahoma", 9, false, true);
                styleOdd.ForeColor = Colors.Blue;

                var styleEven       = new XLStyle(book);
                styleEven.Font      = new XLFont("Tahoma", 9, true, false);
                styleEven.ForeColor = Colors.Red;
                styleEven.BackColor = Colors.Yellow;

                // step 3: write content and format into some cells
                for (int i = 0; i < 30; i++)
                {
                    XLCell cell = sheet[i, 0];
                    cell.Value  = i + 1;
                    cell.Style  = ((i + 1) % 2 == 0) ? styleEven : styleOdd;
                }
            });
        }
Exemplo n.º 4
0
 /// <summary>
 /// Return the Excel type formatting string for the current options (null if not defined)
 /// </summary>
 /// <param name="options">The options to use when converting.</param>
 /// <param name="acceptsNativeType">True if the type converter will pass the native type through to Excel on writing, false if conversion is required.</param>
 /// <param name="convertedType">The type that we are converting from</param>
 /// <returns>The Excel formatting string for the object, null to use default formatting.</returns>
 public static string DefaultFormatString(
     TypeConverterOptions options,
     bool acceptsNativeType,
     Type convertedType)
 {
     if (acceptsNativeType)
     {
         if (options.NumberFormat != null)
         {
             var format = XLStyle.FormatDotNetToXL(options.NumberFormat, convertedType, options.CultureInfo);
             if (!string.IsNullOrEmpty(format))
             {
                 return(format);
             }
         }
         else if (options.DateFormat != null)
         {
             var format = XLStyle.FormatDotNetToXL(options.DateFormat, convertedType, options.CultureInfo);
             if (!string.IsNullOrEmpty(format))
             {
                 return(format);
             }
         }
     }
     return(null);
 }
        private void _btnHello_Click(object sender, RoutedEventArgs e)
        {
            // step 1: create a new workbook
            _book = new C1XLBook();

            // step 2: get the sheet that was created by default, give it a name
            XLSheet sheet = _book.Sheets[0];

            sheet.Name = Strings.SheetName;

            // step 3: create styles for odd and even values
            XLStyle styleOdd = new XLStyle(_book);

            styleOdd.Font      = new XLFont("Tahoma", 9, false, true);
            styleOdd.ForeColor = Color.FromArgb(255, 0, 0, 255);
            XLStyle styleEven = new XLStyle(_book);

            styleEven.Font      = new XLFont("Tahoma", 9, true, false);
            styleEven.ForeColor = Color.FromArgb(255, 255, 0, 0);

            // step 4: write content and format into some cells
            for (int i = 0; i < 100; i++)
            {
                XLCell cell = sheet[i, 0];
                cell.Value = i + 1;
                cell.Style = ((i + 1) % 2 == 0) ? styleEven : styleOdd;
            }

            // step 5: allow user to save the file
            _tbContent.Text = Strings.DataCreatedTip;
            RefreshView();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Update an Excel cell style with the passed in attributes
        /// </summary>
        /// <param name="cellStyle">Place to store the cell style</param>
        /// <param name="format">Optional formatting string for the cell</param>
        /// <param name="fontStyle">Optional font style for the cell</param>
        /// <param name="fontSize">Optional font size for the cell</param>
        /// <param name="fontName">Optional font name for the cell</param>
        private void UpdateStyle(
            ref XLStyle cellStyle,
            string format       = null,
            FontStyle?fontStyle = null,
            float?fontSize      = null,
            string fontName     = null)
        {
            // Set up native formatting if provided
            if (!string.IsNullOrEmpty(format))
            {
                if (cellStyle == null)
                {
                    cellStyle = new XLStyle(_book);
                }
                cellStyle.Format = format;
            }

            // Apply font styling if defined
            if (fontStyle != null || fontSize != null || fontName != null)
            {
                if (cellStyle == null)
                {
                    cellStyle = new XLStyle(_book);
                }
                var defaultFont = _book.DefaultFont;
                var name        = fontName ?? defaultFont.Name;
                var size        = fontSize ?? defaultFont.SizeInPoints;
                var style       = fontStyle ?? defaultFont.Style;
                cellStyle.Font = new Font(name, size, style);
            }
        }
        public void exportarConsolidado(DataTable dtDatos, string ruta)
        {
            this.oBook      = new C1XLBook();
            this.sheet      = this.oBook.Sheets[0];
            this.sheet.Name = "Migración de Inventarios";
            this.crearEncabezados(dtDatos);
            string empty = string.Empty;

            for (int index1 = 0; index1 < dtDatos.Rows.Count; ++index1)
            {
                for (int index2 = 0; index2 < dtDatos.Columns.Count; ++index2)
                {
                    string str = dtDatos.Rows[index1][index2].ToString();
                    new XLColumn().Width = 125;
                    XLCell  xlCell  = this.sheet[index1 + 3, index2];
                    XLStyle xlStyle = new XLStyle(this.oBook);
                    xlStyle.WordWrap = false;
                    if (index2 == 3 || index2 == 4 || (index2 == 5 || index2 == 6) || index2 == 7 || index2 == 8)
                    {
                        xlStyle.Format    = "0,0.0";
                        xlStyle.AlignHorz = XLAlignHorzEnum.Right;
                        xlCell.Value      = (object)(string.IsNullOrEmpty(str) ? Decimal.Zero : Convert.ToDecimal(str));
                    }
                    else
                    {
                        xlStyle.AlignHorz = XLAlignHorzEnum.Left;
                        xlCell.Value      = (object)str;
                    }
                    xlCell.Style = xlStyle;
                }
            }
            this.AutoSizeColumns(this.sheet);
            this.oBook.Save(ruta);
            Process.Start(ruta);
        }
Exemplo n.º 8
0
        public static XLStyle Get_Style(C1XLBook book, float FontSize, FontStyle fontstyle
                                        , C1.C1Excel.XLAlignVertEnum AlignVert, C1.C1Excel.XLAlignHorzEnum AlignHorz
                                        , Boolean WrapText, Boolean Border, string format)
        {
            XLStyle style = new XLStyle(book);

            style.Font      = new Font("Tahoma", FontSize, fontstyle);
            style.ForeColor = Color.Black;

            style.AlignVert = AlignVert;
            style.AlignHorz = AlignHorz;
            style.WordWrap  = WrapText;
            if (Border)
            {
                style.BorderBottom = XLLineStyleEnum.Thin;
                style.BorderLeft   = XLLineStyleEnum.Thin;
                style.BorderRight  = XLLineStyleEnum.Thin;
                style.BorderTop    = XLLineStyleEnum.Thin;
            }
            if (format != "" && format != null)
            {
                style.Format = format;
            }
            return(style);
        }
        private void btnFormulas_Click(object sender, RoutedEventArgs e)
        {
            SaveBook(book =>
            {
                // first sheet
                var sheet = book.Sheets[0];

                // column width in twips
                sheet.Columns[0].Width = 2000;
                sheet.Columns[1].Width = 2200;

                // string formulas
                string s          = "String:";
                sheet[0, 0].Value = s;
                sheet[1, 0].Value = s;
                sheet[2, 0].Value = s;

                sheet[0, 1].Value = "apples";
                sheet[1, 1].Value = "and";
                sheet[2, 1].Value = "oranges";

                s = "String formula:";
                sheet[4, 0].Value = s;
                sheet[5, 0].Value = s;

                sheet[4, 1].Value   = "apples and oranges";
                sheet[5, 1].Value   = "apples an";
                sheet[4, 1].Formula = "CONCATENATE(B1,\" \",B2, \" \",B3)";
                sheet[5, 1].Formula = "LEFT(B5,9)";

                // simple formulas
                sheet[7, 0].Value   = "Formula: 5!";
                sheet[7, 1].Value   = 120;
                sheet[7, 1].Formula = "1*2*3*4*5";

                sheet[8, 0].Value   = "Formula: 12/0";
                sheet[8, 1].Value   = 0;
                sheet[8, 1].Formula = "12/0";

                sheet[9, 0].Value   = "Formula: 1 = 1";
                sheet[9, 1].Value   = true;
                sheet[9, 1].Formula = "1=1";

                sheet[10, 0].Value   = "Formula: 1 = 2";
                sheet[10, 1].Value   = false;
                sheet[10, 1].Formula = "1 = 2";

                // now function
                sheet[12, 0].Value   = "Formula: Now()";
                sheet[12, 1].Value   = DateTime.Now;
                sheet[12, 1].Formula = "Now()";

                var style          = new XLStyle(book);
                var dtfi           = CultureInfo.CurrentCulture.DateTimeFormat;
                style.Format       = XLStyle.FormatDotNetToXL(dtfi.ShortDatePattern + " " + dtfi.ShortTimePattern);
                sheet[12, 1].Style = style;
            });
        }
Exemplo n.º 10
0
        public static XLStyle Get_StyleStringNoneAlignRight(C1XLBook book)
        {
            XLStyle style = new XLStyle(book);

            style.Font      = new Font("Tahoma", 10, FontStyle.Regular);
            style.AlignVert = XLAlignVertEnum.Center;
            style.AlignHorz = XLAlignHorzEnum.Right;
            return(style);
        }
Exemplo n.º 11
0
        public static XLStyle Get_StyleTilte(C1XLBook book)
        {
            XLStyle style = new XLStyle(book);

            style.Font      = new Font("Tahoma", 14, FontStyle.Bold);
            style.ForeColor = Color.Black;
            style.AlignVert = XLAlignVertEnum.Center;
            style.AlignHorz = XLAlignHorzEnum.Center;
            return(style);
        }
Exemplo n.º 12
0
        public static XLStyle Get_StyleStringNoneWordWrap(C1XLBook book)
        {
            XLStyle style = new XLStyle(book);

            style.Font      = new Font("Tahoma", 10, FontStyle.Regular);
            style.AlignVert = XLAlignVertEnum.Top;
            style.AlignHorz = XLAlignHorzEnum.Left;
            style.WordWrap  = true;
            return(style);
        }
Exemplo n.º 13
0
        public static XLStyle Get_StyleTilteBorderBotton(C1XLBook book)
        {
            XLStyle style = new XLStyle(book);

            style.Font         = new Font("Tahoma", 14, FontStyle.Regular);
            style.BorderBottom = XLLineStyleEnum.Thin;
            style.ForeColor    = Color.Black;
            style.AlignVert    = XLAlignVertEnum.Center;
            style.AlignHorz    = XLAlignHorzEnum.Center;

            return(style);
        }
Exemplo n.º 14
0
        private void AutoSizeColumns(XLSheet sheet)
        {
            for (int c = 0; c < sheet.Columns.Count; c++)
            {
                int colWidth = -1;
                for (int r = 0; r < sheet.Rows.Count; r++)
                {
                    object value = sheet[r, c].Value;
                    if (value != null)
                    {
                        // get value (unformatted at this point)
                        string text = value.ToString();

                        // format value if cell has a style with format set
                        var s = sheet[r, c].Style;
                        if (s != null && s.Format.Length > 0 && value is IFormattable)
                        {
                            string fmt = XLStyle.FormatXLToDotNet(s.Format);
                            text = ((IFormattable)value).ToString(fmt, CultureInfo.CurrentCulture);
                        }

                        // get font (default or style)
                        var font = this._book.DefaultFont;
                        if (s != null && s.Font != null)
                        {
                            font = s.Font;
                        }

                        // measure string (add a little tolerance)
                        _tblMeasure.FontFamily = new FontFamily(font.FontName);
                        _tblMeasure.FontSize   = 3 * font.FontSize / 2;
                        _tblMeasure.FontWeight = font.Bold ? FontWeights.Bold : FontWeights.Normal;
                        _tblMeasure.FontStyle  = font.Italic ? FontStyles.Italic : FontStyles.Normal;
                        _tblMeasure.Text       = text;

                        // keep widest so far
                        int w = (int)(_tblMeasure.ActualWidth);
                        if (w > colWidth)
                        {
                            colWidth = w;
                        }
                    }
                }

                // done measuring, set column width
                if (colWidth > -1)
                {
                    sheet.Columns[c].Width = C1XLBook.PixelsToTwips(colWidth);
                }
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Set an entire column to a specific format. By default Excel defines the
        /// cell style in the following order; cell, row, column, worksheet default
        /// </summary>
        /// <param name="col">Column to set the format for</param>
        /// <param name="numberFormat">Optional number formatting string for the cell</param>
        /// <param name="dateFormat">Optional DateTime formatting string for the cell</param>
        /// <param name="fontStyle">Optional font style for the cell</param>
        /// <param name="fontSize">Optional font size for the cell</param>
        /// <param name="fontName">Optional font name for the cell</param>
        public void SetColumnFormat(
            int col,
            string numberFormat = null,
            string dateFormat   = null,
            FontStyle?fontStyle = null,
            float?fontSize      = null,
            string fontName     = null)
        {
            var     format = XLStyle.FormatDotNetToXL(numberFormat ?? dateFormat);
            XLStyle style  = null;

            UpdateStyle(ref style, format, fontStyle, fontSize, fontName);
            _sheet.Columns[col].Style = style;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Set an entire row to a specific format. By default Excel defines the
        /// cell style in the following order; cell, row, column, worksheet default
        /// </summary>
        /// <param name="row">Row to set the format for</param>
        /// <param name="numberFormat">Optional number formatting string for the cell</param>
        /// <param name="dateFormat">Optional DateTime formatting string for the cell</param>
        /// <param name="fontStyle">Optional font style for the cell</param>
        /// <param name="fontSize">Optional font size for the cell</param>
        /// <param name="fontName">Optional font name for the cell</param>
        public void SetRowFormat(
            int row,
            string numberFormat = null,
            string dateFormat   = null,
            FontStyle?fontStyle = null,
            float?fontSize      = null,
            string fontName     = null)
        {
            var     format = XLStyle.FormatDotNetToXL(numberFormat ?? dateFormat);
            XLStyle style  = null;

            UpdateStyle(ref style, format, fontStyle, fontSize, fontName);
            _sheet.Rows[row].Style = style;
        }
Exemplo n.º 17
0
        public static XLStyle Get_StyleCaptionR(C1XLBook book)
        {
            XLStyle style = new XLStyle(book);

            style.Font         = new Font("Tahoma", 11, FontStyle.Bold);
            style.BorderBottom = XLLineStyleEnum.Thin;
            style.BorderLeft   = XLLineStyleEnum.Thin;
            style.BorderRight  = XLLineStyleEnum.Thin;
            style.BorderTop    = XLLineStyleEnum.Thin;
            style.ForeColor    = Color.Black;
            style.AlignVert    = XLAlignVertEnum.Center;
            style.AlignHorz    = XLAlignHorzEnum.Right;
            return(style);
        }
 public void CrearArchivo(DataTable dtDatos, string ruta, bool pVerCosto)
 {
     try
     {
         this.oBook      = new C1XLBook();
         this.sheet      = this.oBook.Sheets[0];
         this.sheet.Name = "Migración de Inventarios";
         this.crearEncabezados(dtDatos);
         string empty = string.Empty;
         for (int index1 = 0; index1 < dtDatos.Rows.Count; ++index1)
         {
             for (int index2 = 0; index2 < dtDatos.Columns.Count; ++index2)
             {
                 if ((index2 != 20 || pVerCosto) && (index2 != 21 || pVerCosto))
                 {
                     string str = dtDatos.Rows[index1][index2].ToString();
                     new XLColumn().Width = 125;
                     XLCell  xlCell  = this.sheet[index1 + 3, index2];
                     XLStyle xlStyle = new XLStyle(this.oBook);
                     xlStyle.WordWrap = false;
                     if (index2 == 2 || index2 == 3 || (index2 == 4 || index2 == 5) || index2 == 20 || index2 == 21)
                     {
                         xlStyle.Format    = "0,0.0";
                         xlStyle.AlignHorz = XLAlignHorzEnum.Right;
                         xlCell.Value      = (object)(string.IsNullOrEmpty(str) ? Decimal.Zero : Convert.ToDecimal(str));
                     }
                     else if (index2 == 22 || index2 == 23)
                     {
                         xlStyle.AlignHorz = XLAlignHorzEnum.Right;
                         xlCell.Value      = (object)(string.IsNullOrEmpty(str) ? 0 : Convert.ToInt32(str));
                     }
                     else
                     {
                         xlStyle.AlignHorz = XLAlignHorzEnum.Left;
                         xlCell.Value      = (object)str;
                     }
                     xlCell.Style = xlStyle;
                 }
             }
         }
         this.AutoSizeColumns(this.sheet);
         this.oBook.Save(ruta);
         Process.Start(ruta);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Exemplo n.º 19
0
        /// <summary>
        /// 自动设置列宽
        /// </summary>
        /// <param name="sheet"></param>
        private void AutoSizeColumns(XLSheet sheet)
        {
            using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
            {
                for (int c = 0; c < sheet.Columns.Count; c++)
                {
                    int colWidth = -1;
                    for (int r = 0; r < sheet.Rows.Count; r++)
                    {
                        object value = sheet[r, c].Value;
                        if (value != null)
                        {
                            // get value (unformatted at this point)
                            string text = value.ToString();

                            // format value if cell has a style with format set
                            C1.C1Excel.XLStyle s = sheet[r, c].Style;
                            if (s != null && s.Format.Length > 0 && value is IFormattable)
                            {
                                string fmt = XLStyle.FormatXLToDotNet(s.Format);
                                text = ((IFormattable)value).ToString(fmt, CultureInfo.CurrentCulture);
                            }

                            // get font (default or style)
                            Font font = this.c1XLBook1.DefaultFont;
                            if (s != null && s.Font != null)
                            {
                                font = s.Font;
                            }

                            // measure string (add a little tolerance)
                            Size sz = Size.Ceiling(g.MeasureString(text + "XX", font));

                            // keep widest so far
                            if (sz.Width > colWidth)
                            {
                                colWidth = sz.Width;
                            }
                        }
                    }

                    // done measuring, set column width
                    if (colWidth > -1)
                    {
                        sheet.Columns[c].Width = C1XLBook.PixelsToTwips(colWidth);
                    }
                }
            }
        }
Exemplo n.º 20
0
        public static XLStyle Get_StyleString(C1XLBook book, Boolean WordWrap)
        {
            XLStyle style = new XLStyle(book);

            style.Font         = new Font("Tahoma", 10, FontStyle.Regular);
            style.BorderBottom = XLLineStyleEnum.Thin;
            style.BorderLeft   = XLLineStyleEnum.Thin;
            style.BorderRight  = XLLineStyleEnum.Thin;
            style.BorderTop    = XLLineStyleEnum.Thin;
            style.ForeColor    = Color.Black;
            style.AlignVert    = XLAlignVertEnum.Center;
            style.AlignHorz    = XLAlignHorzEnum.Left;
            style.WordWrap     = WordWrap;
            return(style);
        }
Exemplo n.º 21
0
        public static XLStyle Get_StyleNumber(C1XLBook book, int size)
        {
            XLStyle style = new XLStyle(book);

            style.Font         = new Font("Tahoma", size, FontStyle.Regular);
            style.BorderBottom = XLLineStyleEnum.Thin;
            style.BorderLeft   = XLLineStyleEnum.Thin;
            style.BorderRight  = XLLineStyleEnum.Thin;
            style.BorderTop    = XLLineStyleEnum.Thin;
            style.ForeColor    = Color.Black;
            style.Format       = "#,###,###";
            style.AlignVert    = XLAlignVertEnum.Center;
            style.AlignHorz    = XLAlignHorzEnum.Right;
            return(style);
        }
Exemplo n.º 22
0
        public static XLStyle Get_StyleLongDate(C1XLBook book)
        {
            XLStyle style = new XLStyle(book);

            style.Font         = new Font("Tahoma", 10, FontStyle.Regular);
            style.BorderBottom = XLLineStyleEnum.Thin;
            style.BorderLeft   = XLLineStyleEnum.Thin;
            style.BorderRight  = XLLineStyleEnum.Thin;
            style.BorderTop    = XLLineStyleEnum.Thin;
            style.ForeColor    = Color.Black;
            style.Format       = "yyyy/MM/dd HH:mm";
            style.AlignVert    = XLAlignVertEnum.Center;
            style.AlignHorz    = XLAlignHorzEnum.Center;
            return(style);
        }
Exemplo n.º 23
0
        public static XLStyle TotalStyle(C1XLBook book)
        {
            XLStyle s = new XLStyle(book)
            {
                AlignHorz = XLAlignHorzEnum.Center,
                AlignVert = XLAlignVertEnum.Center
            };

            s.SetBorderStyle(XLLineStyleEnum.Thin);
            s.SetBorderColor(Color.Black);
            s.Font      = new Font("Tahoma", (float)(7), FontStyle.Bold);
            s.BackColor = Color.Yellow;
            //s.Format = "s";
            return(s);
        }
Exemplo n.º 24
0
        public static XLStyle RedStyle(C1XLBook book)
        {
            XLStyle s = new XLStyle(book)
            {
                AlignHorz = XLAlignHorzEnum.Center,
                AlignVert = XLAlignVertEnum.Center
            };

            s.SetBorderStyle(XLLineStyleEnum.Thin);
            s.SetBorderColor(Color.Black);
            s.Font      = new Font("Tahoma", Convert.ToSingle(7), FontStyle.Regular);
            s.BackColor = Color.Red;
            //s.Format = "s";
            return(s);
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            // clear book
            c1XLBook1.Clear();

            // add some styles
            XLStyle s1 = new XLStyle(c1XLBook1);
            XLStyle s2 = new XLStyle(c1XLBook1);
            XLStyle s3 = new XLStyle(c1XLBook1);

            s1.Format = "#,##0.00000";
            s2.Format = "#,##0.00000";
            s2.Font   = new Font("Courier New", 14);
            s3.Format = "dd-MMM-yy";

            // populate sheet with some random values
            C1.C1Excel.XLSheet sheet = c1XLBook1.Sheets[0];
            Random             r     = new Random();

            for (int i = 0; i < 100; i++)
            {
                sheet[i, 0].Value = r.NextDouble() * 100000;
                sheet[i, 0].Style = (i % 13 == 0)? s2 : s1;
            }
            for (int i = 0; i < 100; i++)
            {
                sheet[i, 1].Value = new DateTime(2005, r.Next(1, 12), r.Next(1, 28));
                sheet[i, 1].Style = s3;
            }

            string tempdir = Application.ExecutablePath.Substring(0,
                                                                  Application.ExecutablePath.LastIndexOf("\\") + 1);

            // save with default column widths
            c1XLBook1.Save(tempdir + @"defaultWidth.xls");

            // autosize columns
            AutoSizeColumns(sheet);

            // save again after autosizing
            c1XLBook1.Save(tempdir + @"autoSized.xls");

            // show the autosized version
            System.Diagnostics.Process.Start(tempdir + @"autoSized.xls");
        }
Exemplo n.º 26
0
        private void _btCreate_Click(object sender, RoutedEventArgs e)
        {
            // create new workbook
            if (_book == null)
            {
                _book = new C1XLBook();
            }

            // clear the book
            _book.Clear();

            // add some styles
            XLStyle s1 = new XLStyle(_book);
            XLStyle s2 = new XLStyle(_book);
            XLStyle s3 = new XLStyle(_book);

            s1.Format = "#,##0.00000";
            s2.Format = "#,##0.00000";
            s2.Font   = new XLFont("Courier New", 14);
            s3.Format = "dd-MMM-yy";

            // populate sheet with some random values
            XLSheet sheet = _book.Sheets[0];
            Random  r     = new Random();

            for (int i = 0; i < 100; i++)
            {
                sheet[i, 0].Value = r.NextDouble() * 100000;
                sheet[i, 0].Style = (i % 13 == 0) ? s2 : s1;
            }
            for (int i = 0; i < 100; i++)
            {
                sheet[i, 1].Value = new DateTime(2005, r.Next(1, 12), r.Next(1, 28));
                sheet[i, 1].Style = s3;
            }

            // automatic sizing
            AutoSizeColumns(sheet);

            // allow save the file
            _lblStatus.Text    = "You can save workbook";
            _btnSave.IsEnabled = true;
        }
Exemplo n.º 27
0
        public static XLStyle ToXLStyle(this Style style, C1XLBook host)
        {
            var c1Style = new XLStyle(host);

            if (style.NumberFormat.HasValue)
            {
                c1Style.Format = style.NumberFormat.Value.ToString();
            }
            if (style.HAlign.HasValue)
            {
                c1Style.AlignHorz = style.HAlign.Value.ToXLAlignH();
            }
            if (style.VAlign.HasValue)
            {
                c1Style.AlignVert = style.VAlign.Value.ToXLAlignV();
            }
            // TODO: other styles
            return(c1Style);
        }
Exemplo n.º 28
0
        public static XLStyle FootNameStyle(C1XLBook book)
        {
            if (book == null)
            {
                throw new ArgumentNullException("book", "book is null.");
            }

            XLStyle style = new XLStyle(book)
            {
                AlignHorz = XLAlignHorzEnum.Left,
                AlignVert = XLAlignVertEnum.Center,
                ForeColor = Color.Black,
                Font      = new Font("Arial", (float)7)
            };

            style.SetBorderStyle(XLLineStyleEnum.None);
            style.SetBorderColor(Color.Black);

            return(style);
        }
Exemplo n.º 29
0
        private string CreateExcelFile()
        {
            //clear Excel book, remove the single blank sheet
            _c1xl.Clear();
            _c1xl.Sheets.Clear();
            _c1xl.DefaultFont = new Font("Tahoma", 8);

            //create Excel styles
            _styTitle  = new XLStyle(_c1xl);
            _styHeader = new XLStyle(_c1xl);
            _styMoney  = new XLStyle(_c1xl);
            _styOrder  = new XLStyle(_c1xl);

            //set up styles
            _styTitle.Font       = new Font(_c1xl.DefaultFont.Name, 15, FontStyle.Bold);
            _styTitle.ForeColor  = Color.Blue;
            _styHeader.Font      = new Font(_c1xl.DefaultFont, FontStyle.Bold);
            _styHeader.ForeColor = Color.White;
            _styHeader.BackColor = Color.DarkGray;
            _styMoney.Format     = XLStyle.FormatDotNetToXL("c");
            _styOrder.Font       = _styHeader.Font;
            _styOrder.ForeColor  = Color.Red;

            //create report with one sheet per category
            DataTable dt = GetCategories();

            foreach (DataRow dr in dt.Rows)
            {
                CreateSheet(dr);
            }

            //save xls file

            string filename = GetTempFileName(".xls");

            _c1xl.Save(filename);

            return(filename);
        }
Exemplo n.º 30
0
        private string CreateExcelFile()
        {
            //clear Excel book, remove the single blank sheet
            _c1xl.Clear();
            _c1xl.Sheets.Clear();
            _c1xl.DefaultFont = new Font("Tahoma", 8);

            //create Excel styles
            _styTitle = new XLStyle(_c1xl);
            _styHeader = new XLStyle(_c1xl);
            _styMoney = new XLStyle(_c1xl);
            _styOrder = new XLStyle(_c1xl);

            //set up styles
            _styTitle.Font = new Font(_c1xl.DefaultFont.Name, 15, FontStyle.Bold);
            _styTitle.ForeColor = Color.Blue;
            _styHeader.Font = new Font(_c1xl.DefaultFont, FontStyle.Bold);
            _styHeader.ForeColor = Color.White;
            _styHeader.BackColor = Color.DarkGray;
            _styMoney.Format = XLStyle.FormatDotNetToXL("c");
            _styOrder.Font = _styHeader.Font;
            _styOrder.ForeColor = Color.Red;

            //create report with one sheet per category
            DataTable dt = GetCategories();
            foreach (DataRow dr in dt.Rows)
            {
                CreateSheet(dr);
            }

            //save xls file
            string uid = System.Guid.NewGuid().ToString();
            string filename = Server.MapPath("~") + "\\Temp\\testexcel" + uid + ".xls"; 
            _c1xl.Save(filename);
            
            return filename;

        }
 private void AutoSizeColumns(XLSheet sheet)
 {
     using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero))
     {
         for (int index1 = 0; index1 < sheet.Columns.Count; ++index1)
         {
             int num = -1;
             for (int index2 = 0; index2 < sheet.Rows.Count; ++index2)
             {
                 object obj = sheet[index2, index1].Value;
                 if (obj != null)
                 {
                     string  str   = obj.ToString();
                     XLStyle style = sheet[index2, index1].Style;
                     if (style != null && style.Format.Length > 0 && obj is IFormattable)
                     {
                         string dotNet = XLStyle.FormatXLToDotNet(style.Format);
                         str = ((IFormattable)obj).ToString(dotNet, (IFormatProvider)CultureInfo.CurrentCulture);
                     }
                     Font font = this.oBook.DefaultFont;
                     if (style != null && style.Font != null)
                     {
                         font = style.Font;
                     }
                     Size size = Size.Ceiling(graphics.MeasureString(str + "XX", font));
                     if (size.Width > num)
                     {
                         num = size.Width;
                     }
                 }
             }
             if (num > -1)
             {
                 sheet.Columns[index1].Width = C1XLBook.PixelsToTwips((double)num);
             }
         }
     }
 }
        protected void btnView_Click(object sender, EventArgs e)
        {
            mvMessage.CheckRequired(txtContractDate, "Ngày xuất HĐ : Danh mục phải nhập");
            mvMessage.CheckRequired(txtContractNo, "Hợp đồng số : Danh mục phải nhập");
            mvMessage.CheckRequired(txtRate, "Tỉ giá quy đổi USD->VND : Danh mục phải nhập");
            mvMessage.CheckRequired(txtRateDate, "Thời gian quy đổi: Danh mục phải nhập");
            if (!mvMessage.IsValid) return;

            C1XLBook xlbBook = new C1XLBook();
            string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\BillPhongHop.xlsx");
            if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BillPhongHop"))
            {
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BillPhongHop"));
            }

            decimal[] LastSumPriceVND = { 0, 0, 0 };
            decimal[] LastSumPriceUSD = { 0, 0, 0 };

            XLStyle xlstStyle = new XLStyle(xlbBook);
            xlstStyle.AlignHorz = XLAlignHorzEnum.Center;
            xlstStyle.WordWrap = true;
            xlstStyle.Font = new Font("", 8, FontStyle.Regular);
            xlstStyle.SetBorderColor(Color.Black);
            xlstStyle.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyle.BorderTop = XLLineStyleEnum.Thin;
            xlstStyle.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyle.BorderRight = XLLineStyleEnum.Thin;
            xlstStyle.Format = "#,##0.00_);(#,##0.00)";

            XLStyle xlstStyleSum = new XLStyle(xlbBook);
            xlstStyleSum.AlignHorz = XLAlignHorzEnum.Right;
            xlstStyleSum.AlignVert = XLAlignVertEnum.Center;
            xlstStyleSum.Font = new Font("Times New Roman", 10, FontStyle.Bold);
            xlstStyleSum.SetBorderColor(Color.Black);
            xlstStyleSum.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyleSum.BorderTop = XLLineStyleEnum.Thin;
            xlstStyleSum.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyleSum.BorderRight = XLLineStyleEnum.Thin;
            xlstStyleSum.WordWrap = true;
            xlstStyleSum.Format = "#,##0.00_);(#,##0.00)";

            string strDT = DateTime.Now.ToString("yyyyMMddHHmmss");
            string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"BillPhongHop\BillPhongHop" + "_" + lnbCustomerId.Text + "_" + strDT + ".xlsx";
            string strFilePathExport = @"../../Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/BillPhongHop/BillPhongHop" + "_" + lnbCustomerId.Text + "_" + strDT + ".xlsx";

            string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath);

            //string fileNameDes = HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\TongHopDienTich" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx");
            File.Copy(fileName, fileNameDes);

            xlbBook.Load(fileNameDes);
            XLSheet xlsSheet = xlbBook.Sheets["HoaDon"];

            int k = 2;
            xlsSheet[1, 6 + k].Value = xlsSheet[1, 6 + k].Value.ToString().Replace("{%NGAY%}", DateTime.Today.ToString("dd"));
            xlsSheet[1, 6 + k].Value = xlsSheet[1, 6 + k].Value.ToString().Replace("{%THANG%}", DateTime.Today.ToString("MM"));
            xlsSheet[1, 6 + k].Value = xlsSheet[1, 6 + k].Value.ToString().Replace("{%NAM%}", DateTime.Today.ToString("yyyy"));

            using (SqlDatabase db = new SqlDatabase())
            {
                DataSet ds = new DataSet();
                string sql = string.Empty;

                sql = " SELECT Name, ContactName";
                sql += " FROM Customer";
                sql += " WHERE CustomerId = '" + lnbCustomerId.Text + "' ";

                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    if (ds != null)
                    {
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            string Name = rowType[0].ToString();
                            string ContactName = rowType[1].ToString();

                            xlsSheet[6, 0].Value = xlsSheet[6, 0].Value.ToString().Replace("{%TEN_CONG_TY%}", Name);
                            xlsSheet[7, 0].Value = xlsSheet[7, 0].Value.ToString().Replace("{%NGUOI_DAI_DIEN%}", ContactName);

                            xlsSheet[9, 0].Value = xlsSheet[9, 0].Value.ToString().Replace("{%NGAY_HOP_DONG%}", lblBookingDate.Text).Replace("{%HOP_DONG%}", txtContractNo.Text);

                            xlsSheet[11, 0].Value = xlsSheet[11, 0].Value.ToString().Replace("{%GIO_TU%}", drpHourFrom.SelectedValue);
                            xlsSheet[11, 0].Value = xlsSheet[11, 0].Value.ToString().Replace("{%PHUT_TU%}", drpMinuteFrom.Value);
                            xlsSheet[11, 0].Value = xlsSheet[11, 0].Value.ToString().Replace("{%GIO_DEN%}", drpHourTo.SelectedValue);
                            xlsSheet[11, 0].Value = xlsSheet[11, 0].Value.ToString().Replace("{%PHUT_DEN%}", drpMinuteTo.Value);
                            xlsSheet[11, 0].Value = xlsSheet[11, 0].Value.ToString().Replace("{%NGAY_THUE%}", lblBookingDate.Text);
                        }
                    }
                }

                ds = new DataSet();
                sql = " SELECT Bank,Account,AccountName,Office,OfficeAddress,OfficePhone";
                sql += " FROM Mst_Building";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' ";
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    if (ds != null)
                    {
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            string Bank = rowType["Bank"].ToString();
                            string Account = rowType["Account"].ToString();
                            string AccountName = rowType["AccountName"].ToString();
                            string Office = rowType["Office"].ToString();
                            string OfficeAddress = rowType["OfficeAddress"].ToString();
                            string OfficePhone = rowType["OfficePhone"].ToString();

                            xlsSheet[35, 0].Value = xlsSheet[35, 0].Value.ToString().Replace("{%VAN_PHONG%}", Office);
                            xlsSheet[36, 0].Value = xlsSheet[36, 0].Value.ToString().Replace("{%DIEN_THOAI%}", OfficePhone);

                            xlsSheet[38, 0].Value = xlsSheet[38, 0].Value.ToString().Replace("{%NGAN_HANG%}", Bank);
                            xlsSheet[39, 0].Value = xlsSheet[39, 0].Value.ToString().Replace("{%TEN_TAI_KHOAN%}", AccountName);
                            xlsSheet[40, 0].Value = xlsSheet[40, 0].Value.ToString().Replace("{%SO_TAI_KHOAN%}", Account);
                        }
                    }
                }
                XLCellRange mrCell = new XLCellRange(0, 0, 0, 0);

                xlsSheet[27, 0].Value = xlsSheet[27, 0].Value.ToString().Replace("{%TI_GIA%}", Func.FormatNumber_New(txtRate.Text)).Replace("{%NGAY_AP_DUNG%}", txtRateDate.Text.Substring(0, 10));

                ds = new DataSet();
                sql = " SELECT *";
                sql += " FROM v_BookingRoomInfo";
                sql += " WHERE BookingId = '" + hidId.Value + "' ";

                int j = 0;
                int count = 0;
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    if (ds != null)
                    {
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            if (count >= 1)
                            {
                                xlsSheet.Rows.Insert(18 + 1 + j);
                                j++;
                            }
                            count++;
                            int tmp = 18 + j;

                            string Name = rowType["Name"].ToString();
                            string Regional = rowType["Regional"].ToString();
                            string Floor = rowType["Floor"].ToString();
                            string Area = rowType["Area"].ToString();
                            string PriceUSD = rowType["PriceUSD"].ToString();
                            string PriceVND = rowType["PriceVND"].ToString();
                            string SumUSD = rowType["SumUSD"].ToString();
                            string SumVND = rowType["SumVND"].ToString();
                            string VatUSD = rowType["VatUSD"].ToString();
                            string VatVND = rowType["VatVND"].ToString();
                            string LastPriceUSD = rowType["LastPriceUSD"].ToString();
                            string LastPriceVND = rowType["LastPriceVND"].ToString();
                            string BookingId = rowType["BookingId"].ToString();

                            xlsSheet[tmp, 1].Value = Name;
                            xlsSheet[tmp, 2].Value = Regional;
                            xlsSheet[tmp, 3].Value = Floor;
                            xlsSheet[tmp, 4].Value = rowType["Area"];
                            xlsSheet[tmp, 5].Value = rowType["PriceUSD"];
                            xlsSheet[tmp, 6].Value = rowType["PriceVND"];
                            xlsSheet[tmp, 7].Value = rowType["SumUSD"];
                            xlsSheet[tmp, 8].Value = rowType["SumVND"];
                            xlsSheet[tmp, 9].Value = rowType["VatUSD"];
                            xlsSheet[tmp, 10].Value = rowType["VatVND"];
                            xlsSheet[tmp, 11].Value = rowType["LastPriceUSD"];
                            xlsSheet[tmp, 12].Value = rowType["LastPriceVND"];

                            LastSumPriceVND[0] += Convert.ToDecimal(rowType["LastPriceVND"]);
                            LastSumPriceUSD[0] += Convert.ToDecimal(rowType["LastPriceUSD"]);

                            for (int col = 1; col <= 12; col++)
                            {
                                xlsSheet[tmp, col].Style = xlstStyle;
                            }
                        }
                        mrCell = new XLCellRange(18 + 1 + j, 18 + 1 + j, 1, 10);
                        xlsSheet.MergedCells.Add(mrCell);

                        xlsSheet[18 + 1 + j, 11].Value = LastSumPriceUSD[0];
                        xlsSheet[18 + 1 + j, 12].Value = LastSumPriceVND[0];

                        for (int col = 1; col <= 12; col++)
                        {
                            xlsSheet[18 + 1 + j, col].Style = xlstStyleSum;
                        }
                    }
                }
                XLSheet source = xlbBook.Sheets["tpl"];

                for (int row = 21; row <= 25; row++)
                {
                    for (int col = 0; col <= 12; col++)
                    {
                        xlsSheet[row + j, col].Style = source[row, col].Style;
                        xlsSheet[row + j, col].Value = source[row, col].Value;
                    }
                }

                //XLCellRange mrCell = new XLCellRange(22 + j, 23 + j, 1, 1);
                //xlsSheet.MergedCells.Add(mrCell);

                //mrCell = new XLCellRange(22 + j, 23 + j, 2, 2);
                //xlsSheet.MergedCells.Add(mrCell);

                //mrCell = new XLCellRange(22 + j, 23 + j, 3, 4);
                //xlsSheet.MergedCells.Add(mrCell);

                //mrCell = new XLCellRange(22 + j, 22 + j, 5, 6);
                //xlsSheet.MergedCells.Add(mrCell);

                //mrCell = new XLCellRange(22 + j, 22 + j, 7, 8);
                //xlsSheet.MergedCells.Add(mrCell);

                //mrCell = new XLCellRange(22 + j, 22 + j, 9, 10);
                //xlsSheet.MergedCells.Add(mrCell);

                //mrCell = new XLCellRange(22 + j, 22 + j, 11, 12);
                //xlsSheet.MergedCells.Add(mrCell);

                ds = new DataSet();
                sql = " SELECT  Service, Mount, PriceUSD, PriceVND, SumUSD, SumVND, VatUSD, VatVND, LastPriceUSD, LastPriceVND, Unit";
                sql += " FROM    PaymentBookingService";
                sql += " WHERE BookingId = '" + hidId.Value + "' and (Delflag is null or Delflag = 0)";

                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    if (ds != null)
                    {
                        count = 0;
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            if (count >= 1)
                            {
                                xlsSheet.Rows.Insert(24 + 1 + j);
                                j++;
                            }
                            count++;
                            int tmp = 24 + j;

                            string Service = rowType["Service"].ToString();
                            string Mount = rowType["Mount"].ToString();
                            string Unit = rowType["Unit"].ToString();
                            string PriceUSD = rowType["PriceUSD"].ToString();
                            string PriceVND = rowType["PriceVND"].ToString();
                            string SumUSD = rowType["SumUSD"].ToString();
                            string SumVND = rowType["SumVND"].ToString();
                            string VatUSD = rowType["VatUSD"].ToString();
                            string VatVND = rowType["VatVND"].ToString();
                            string LastPriceUSD = rowType["LastPriceUSD"].ToString();
                            string LastPriceVND = rowType["LastPriceVND"].ToString();

                            xlsSheet[tmp, 1].Value = Service;
                            xlsSheet[tmp, 2].Value = rowType["Mount"];
                            xlsSheet[tmp, 3].Value = Unit;

                            mrCell = new XLCellRange(tmp, tmp, 3, 4);
                            xlsSheet.MergedCells.Add(mrCell);

                            xlsSheet[tmp, 5].Value = rowType["PriceUSD"];
                            xlsSheet[tmp, 6].Value = rowType["PriceVND"];
                            xlsSheet[tmp, 7].Value = rowType["SumUSD"];
                            xlsSheet[tmp, 8].Value = rowType["SumVND"];
                            xlsSheet[tmp, 9].Value = rowType["VatUSD"];
                            xlsSheet[tmp, 10].Value = rowType["VatVND"];
                            xlsSheet[tmp, 11].Value = rowType["LastPriceUSD"];
                            xlsSheet[tmp, 12].Value = rowType["LastPriceVND"];

                            LastSumPriceVND[1] += Convert.ToDecimal(rowType["LastPriceVND"]);
                            LastSumPriceUSD[1] += Convert.ToDecimal(rowType["LastPriceUSD"]);

                            for (int col = 1; col <= 12; col++)
                            {
                                xlsSheet[tmp, col].Style = xlstStyle;
                            }
                        }
                        mrCell = new XLCellRange(24 + 1 + j, 24 + 1 + j, 1, 10);
                        xlsSheet.MergedCells.Add(mrCell);

                        xlsSheet[24 + 1 + j, 11].Value = LastSumPriceUSD[1];
                        xlsSheet[24 + 1 + j, 12].Value = LastSumPriceVND[1];

                        for (int col = 1; col <= 12; col++)
                        {
                            xlsSheet[24 + 1 + j, col].Style = xlstStyleSum;
                        }
                    }
                }

                //////////////////Da Tra
                ds = new DataSet();
                sql = " SELECT  Sum(isnull(MoneyUSD,0)) USD, Sum(isnull(MoneyVND,0)) VND";
                sql += " FROM    Payment";
                sql += " WHERE BookingId = '" + hidId.Value + "' and (Delflag is null or Delflag = 0)";

                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    if (ds != null)
                    {
                        count = 0;
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            int tmp = 29 + j;

                            xlsSheet[tmp, 2].Value = (Func.ParseString(rowType["USD"]) == "" ? 0 : rowType["USD"]);
                            xlsSheet[tmp, 4].Value = (Func.ParseString(rowType["VND"]) == "" ? 0 : rowType["VND"]);

                            LastSumPriceVND[2] += Convert.ToDecimal(Func.ParseString(rowType["VND"]) == "" ? 0 : rowType["VND"]);
                            LastSumPriceUSD[2] += Convert.ToDecimal(Func.ParseString(rowType["USD"]) == "" ? 0 : rowType["USD"]);

                        }
                    }
                }
                //////////////////Da Tra

                xlsSheet[28 + j, 2].Value = Func.FormatNumber_New(LastSumPriceUSD[0] + LastSumPriceUSD[1]);
                xlsSheet[28 + j, 4].Value = Func.FormatNumber_New(LastSumPriceVND[0] + LastSumPriceVND[1]);

                xlsSheet[30 + j, 2].Value = Func.FormatNumber_New(Convert.ToDecimal(txtRate.Text) * (LastSumPriceUSD[0] + LastSumPriceUSD[1] - LastSumPriceUSD[2]));
                xlsSheet[30 + j, 4].Value = Func.FormatNumber_New(LastSumPriceVND[0] + LastSumPriceVND[1] - LastSumPriceVND[2]);

                xlsSheet[31 + j, 3].Value = Func.FormatNumber_New(Convert.ToDecimal(txtRate.Text) * (LastSumPriceUSD[0] + LastSumPriceUSD[1] - LastSumPriceUSD[2]) + (LastSumPriceVND[0] + LastSumPriceVND[1] - LastSumPriceVND[2]));
                xlsSheet[32 + j, 2].Value = Func.docso(Convert.ToInt32(Convert.ToDecimal(txtRate.Text) * (LastSumPriceUSD[0] + LastSumPriceUSD[1] - LastSumPriceUSD[2]) + (LastSumPriceVND[0] + LastSumPriceVND[1] - LastSumPriceVND[2]))).ToUpper();

                //xlsSheet[28 + j, 2].Style = xlstStyleSum;
                //xlsSheet[28 + j, 4].Style = xlstStyleSum;

                //xlsSheet[30 + j, 2].Style = xlstStyleSum;
                //xlsSheet[30 + j, 4].Style = xlstStyleSum;

                //xlsSheet[31 + j, 3].Style = xlstStyleSum;

                xlbBook.Save(fileNameDes);
                ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true);
            }
        }
Exemplo n.º 33
0
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExport2_Click(object sender, EventArgs e)
        {
            string buildingId = Func.ParseString(Session["__BUILDINGID__"]);
            string sql = "Select CustomerId, Name From Customer Where BuildingId = '" + buildingId + "' and DelFlag = 0 order by CustomerId";
            Hashtable CusList = new Hashtable();
            DataTable dtCus = DbHelper.GetDataTable(sql);
            foreach (DataRow drCus in dtCus.Rows)
            {
                if (!CusList.Contains(drCus["CustomerId"].ToString()))
                {
                    CusList.Add(drCus["CustomerId"].ToString(), drCus["Name"].ToString());
                }
            }

            Hashtable PaymentList = new Hashtable();
            sql = "Select * from v_PaymentBillDetailGeneral Where BuildingId = '" + buildingId + "' order by CustomerId";

            DataTable dt = DbHelper.GetDataTable(sql);
            foreach (DataRow dr in dt.Rows)
            {
                string CustomerId = dr["CustomerId"].ToString();
                string key = CustomerId;
                DeptInfo tmp;

                if (!PaymentList.Contains(key))
                {
                    tmp = new DeptInfo();
                    tmp.CustomerId = CustomerId;
                    tmp.Customer = Func.ParseString(CusList[CustomerId]);
                    PaymentList.Add(key, tmp);
                }
                string PaymentType = dr["PaymentType"].ToString();

                decimal MoneyUSD = Convert.ToDecimal(dr["MoneyUSD"]);
                decimal MoneyVND = Convert.ToDecimal(dr["MoneyVND"]);
                decimal PaidUSD = Convert.ToDecimal(dr["PaidUSD"]);
                decimal PaidVND = Convert.ToDecimal(dr["PaidVND"]);

                tmp = (DeptInfo)PaymentList[key];
                switch (PaymentType)
                {
                    case "1":
                        tmp.RentUSD = MoneyUSD;
                        tmp.RentVND = MoneyVND;
                        tmp.RentPaidUSD = PaidUSD;
                        tmp.RentPaidVND = PaidVND;
                        break;
                    case "2":
                        tmp.ManagerUSD = MoneyUSD;
                        tmp.ManagerVND = MoneyVND;
                        tmp.ManagerPaidUSD = PaidUSD;
                        tmp.ManagerPaidVND = PaidVND;
                        break;
                    case "3":
                        tmp.ParkingUSD = MoneyUSD;
                        tmp.ParkingVND = MoneyVND;
                        tmp.ParkingPaidUSD = PaidUSD;
                        tmp.ParkingPaidVND = PaidVND;
                        break;
                    case "4":
                        tmp.ExtraUSD = MoneyUSD;
                        tmp.ExtraVND = MoneyVND;
                        tmp.ExtraPaidUSD = PaidUSD;
                        tmp.ExtraPaidVND = PaidVND;
                        break;
                    case "5":
                        tmp.ElecUSD = MoneyUSD;
                        tmp.ElecVND = MoneyVND;
                        tmp.ElecPaidUSD = PaidUSD;
                        tmp.ElecPaidVND = PaidVND;
                        break;
                    case "6":
                        tmp.WaterUSD = MoneyUSD;
                        tmp.WaterVND = MoneyVND;
                        tmp.WaterPaidUSD = PaidUSD;
                        tmp.WaterPaidVND = PaidVND;
                        break;
                    case "7":
                        tmp.ServiceUSD = MoneyUSD;
                        tmp.ServiceVND = MoneyVND;
                        tmp.ServicePaidUSD = PaidUSD;
                        tmp.ServicePaidVND = PaidVND;
                        break;
                    case "8":
                        tmp.BookingUSD = MoneyUSD;
                        tmp.BookingVND = MoneyVND;
                        tmp.BookingPaidUSD = PaidUSD;
                        tmp.BookingPaidVND = PaidVND;
                        break;
                    default:
                        break;
                }
            }

            C1XLBook xlbBook = new C1XLBook();

            string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\BaoCaoCongNo_TongQuat.xlsx");
            if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BaoCaoCongNo"))
            {
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BaoCaoCongNo"));
            }

            string strDT = DateTime.Now.ToString("yyyyMMddHHmmss");
            string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BaoCaoCongNo\BaoCaoCongNo_TongQuat" + strDT + ".xlsx";
            string strFilePathExport = "Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/BaoCaoCongNo/BaoCaoCongNo_TongQuat" + strDT + ".xlsx";

            string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath);

            //string fileNameDes = HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\TongHopDienTich" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx");
            File.Copy(fileName, fileNameDes);

            xlbBook.Load(fileNameDes);

            XLStyle xlstStyle2 = new XLStyle(xlbBook);
            xlstStyle2.AlignVert = XLAlignVertEnum.Center;
            xlstStyle2.WordWrap = false;
            xlstStyle2.Font = new Font("", 8, FontStyle.Regular);
            xlstStyle2.SetBorderColor(Color.Black);
            xlstStyle2.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyle2.BorderTop = XLLineStyleEnum.Thin;
            xlstStyle2.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyle2.BorderRight = XLLineStyleEnum.Thin;
            xlstStyle2.Format = "#,##0.00_);(#,##0.00)";

            XLStyle xlstStyle1 = new XLStyle(xlbBook);
            xlstStyle1.AlignVert = XLAlignVertEnum.Center;
            xlstStyle1.WordWrap = false;
            xlstStyle1.Font = new Font("", 8, FontStyle.Regular);
            xlstStyle1.SetBorderColor(Color.Black);
            xlstStyle1.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyle1.BorderTop = XLLineStyleEnum.Thin;
            xlstStyle1.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyle1.BorderRight = XLLineStyleEnum.Thin;
            xlstStyle1.Format = "#,##0.0_);(#,##0.0)";

            XLStyle xlstStyle0 = new XLStyle(xlbBook);
            xlstStyle0.AlignVert = XLAlignVertEnum.Center;
            xlstStyle0.WordWrap = false;
            xlstStyle0.Font = new Font("", 8, FontStyle.Regular);
            xlstStyle0.SetBorderColor(Color.Black);
            xlstStyle0.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyle0.BorderTop = XLLineStyleEnum.Thin;
            xlstStyle0.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyle0.BorderRight = XLLineStyleEnum.Thin;
            xlstStyle0.Format = "#,##0_);(#,##0)";

            XLStyle xlstStyleB2 = new XLStyle(xlbBook);
            xlstStyleB2.AlignHorz = XLAlignHorzEnum.Right;
            xlstStyleB2.AlignVert = XLAlignVertEnum.Center;
            xlstStyleB2.WordWrap = false;
            xlstStyleB2.Font = new Font("", 8, FontStyle.Bold);
            xlstStyleB2.SetBorderColor(Color.Black);
            xlstStyleB2.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyleB2.BorderTop = XLLineStyleEnum.Thin;
            xlstStyleB2.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyleB2.BorderRight = XLLineStyleEnum.Thin;
            xlstStyleB2.Format = "#,##0.00_);(#,##0.00)";

            XLStyle xlstStyleB1 = new XLStyle(xlbBook);
            xlstStyleB1.AlignHorz = XLAlignHorzEnum.Right;
            xlstStyleB1.AlignVert = XLAlignVertEnum.Center;
            xlstStyleB1.WordWrap = false;
            xlstStyleB1.Font = new Font("", 8, FontStyle.Bold);
            xlstStyleB1.SetBorderColor(Color.Black);
            xlstStyleB1.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyleB1.BorderTop = XLLineStyleEnum.Thin;
            xlstStyleB1.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyleB1.BorderRight = XLLineStyleEnum.Thin;
            xlstStyleB1.Format = "#,##0.0_);(#,##0.0)";

            XLStyle xlstStyleB0 = new XLStyle(xlbBook);
            xlstStyleB0.AlignHorz = XLAlignHorzEnum.Right;
            xlstStyleB0.AlignVert = XLAlignVertEnum.Center;
            xlstStyleB0.WordWrap = false;
            xlstStyleB0.Font = new Font("", 8, FontStyle.Bold);
            xlstStyleB0.SetBorderColor(Color.Black);
            xlstStyleB0.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyleB0.BorderTop = XLLineStyleEnum.Thin;
            xlstStyleB0.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyleB0.BorderRight = XLLineStyleEnum.Thin;
            xlstStyleB0.Format = "#,##0_);(#,##0)";

            decimal[] AllSumUsd = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            decimal[] AllSumVnd = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

            string sheet = "BaoCao";

            XLSheet xlsSheet = xlbBook.Sheets[sheet];
            int i = 5;

            xlsSheet[0, 1].Value = xlsSheet[0, 1].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + buildingId + "'"));
            int j = 1;
            foreach (DictionaryEntry tmp in PaymentList)
            {
                string key = (string)tmp.Key;
                DeptInfo dept = (DeptInfo)tmp.Value;

                xlsSheet[i, 0 + j].Value = Func.ParseString(i - 4);
                xlsSheet[i, 1 + j].Value = dept.CustomerId;
                xlsSheet[i, 2 + j].Value = dept.Customer;

                xlsSheet[i, 3 + j].Value = dept.RentUSD;
                xlsSheet[i, 4 + j].Value = dept.RentVND;

                xlsSheet[i, 5 + j].Value = dept.ManagerUSD;
                xlsSheet[i, 6 + j].Value = dept.ManagerVND;

                xlsSheet[i, 7 + j].Value = dept.ParkingUSD;
                xlsSheet[i, 8 + j].Value = dept.ParkingVND;

                xlsSheet[i, 9 + j].Value = dept.ExtraUSD;
                xlsSheet[i, 10 + j].Value = dept.ExtraVND;

                //xlsSheet[i, 11 + j].Value = dept.ElecUSD;
                xlsSheet[i, 11 + j].Value = dept.ElecVND;

                //xlsSheet[i, 13 + j].Value = dept.WaterUSD;
                xlsSheet[i, 12 + j].Value = dept.WaterVND;

                xlsSheet[i, 13 + j].Value = dept.ServiceUSD;
                xlsSheet[i, 14 + j].Value = dept.ServiceVND;

                xlsSheet[i, 15 + j].Value = dept.BookingUSD;
                xlsSheet[i, 16 + j].Value = dept.BookingVND;

                xlsSheet[i, 17 + j].Value = dept.SumUSD();
                xlsSheet[i, 18 + j].Value = dept.SumVND();

                //-----------------------
                xlsSheet[i, j + 19].Value = dept.RentPaidUSD;
                xlsSheet[i, j + 20].Value = dept.RentPaidVND;

                xlsSheet[i, j + 21].Value = dept.ManagerPaidUSD;
                xlsSheet[i, j + 22].Value = dept.ManagerPaidVND;

                xlsSheet[i, j + 23].Value = dept.ParkingPaidUSD;
                xlsSheet[i, j + 24].Value = dept.ParkingPaidVND;

                xlsSheet[i, j + 25].Value = dept.ExtraPaidUSD;
                xlsSheet[i, j + 26].Value = dept.ExtraPaidVND;

                //xlsSheet[i, 11 + j + 18].Value = dept.ElecPaidUSD;
                xlsSheet[i, j + 27].Value = dept.ElecPaidVND;

                //xlsSheet[i, 13 + j + 18].Value = dept.WaterPaidUSD;
                xlsSheet[i, j + 28].Value = dept.WaterPaidVND;

                xlsSheet[i, j + 29].Value = dept.ServicePaidUSD;
                xlsSheet[i, j + 30].Value = dept.ServicePaidVND;

                xlsSheet[i, j + 31].Value = dept.BookingPaidUSD;
                xlsSheet[i, j + 32].Value = dept.BookingPaidVND;

                xlsSheet[i, j + 33].Value = dept.SumPaidUSD();
                xlsSheet[i, j + 34].Value = dept.SumPaidVND();

                xlsSheet[i, j + 35].Value = dept.SumUSD() - dept.SumPaidUSD();
                xlsSheet[i, j + 36].Value = dept.SumVND() - dept.SumPaidVND();

                /////////////////
                AllSumUsd[0] += dept.RentUSD;
                AllSumVnd[0] += dept.RentVND;

                AllSumUsd[1] += dept.ManagerUSD;
                AllSumVnd[1] += dept.ManagerVND;

                AllSumUsd[2] += dept.ParkingUSD;
                AllSumVnd[2] += dept.ParkingVND;

                AllSumUsd[3] += dept.ExtraUSD;
                AllSumVnd[3] += dept.ExtraVND;

                AllSumUsd[4] += dept.ElecUSD;
                AllSumVnd[4] += dept.ElecVND;

                AllSumUsd[5] += dept.WaterUSD;
                AllSumVnd[5] += dept.WaterVND;

                AllSumUsd[6] += dept.ServiceUSD;
                AllSumVnd[6] += dept.ServiceVND;

                AllSumUsd[7] += dept.BookingUSD;
                AllSumVnd[7] += dept.BookingVND;

                AllSumUsd[8] += dept.SumUSD();
                AllSumVnd[8] += dept.SumVND();

                //-----------------------
                AllSumUsd[9] += dept.RentPaidUSD;
                AllSumVnd[9] += dept.RentPaidVND;

                AllSumUsd[10] += dept.ManagerPaidUSD;
                AllSumVnd[10] += dept.ManagerPaidVND;

                AllSumUsd[11] += dept.ParkingPaidUSD;
                AllSumVnd[11] += dept.ParkingPaidVND;

                AllSumUsd[12] += dept.ExtraPaidUSD;
                AllSumVnd[12] += dept.ExtraPaidVND;

                AllSumUsd[13] += dept.ElecPaidUSD;
                AllSumVnd[13] += dept.ElecPaidVND;

                AllSumUsd[14] += dept.WaterPaidUSD;
                AllSumVnd[14] += dept.WaterPaidVND;

                AllSumUsd[15] += dept.ServicePaidUSD;
                AllSumVnd[15] += dept.ServicePaidVND;

                AllSumUsd[16] += dept.BookingPaidUSD;
                AllSumVnd[16] += dept.BookingPaidVND;

                AllSumUsd[17] += dept.SumPaidUSD();
                AllSumVnd[17] += dept.SumPaidVND();

                AllSumUsd[18] += dept.SumUSD() - dept.SumPaidUSD();
                AllSumVnd[18] += dept.SumVND() - dept.SumPaidVND();

                for (int m = 0; m < 37; m++)
                {
                    xlsSheet[i, m + j].Style = xlstStyle1;
                }
                ////////////////////////////////////////////
                xlsSheet[i, 4 + j].Style = xlstStyle0;
                xlsSheet[i, 6 + j].Style = xlstStyle0;
                xlsSheet[i, 8 + j].Style = xlstStyle0;
                xlsSheet[i, 10 + j].Style = xlstStyle0;
                xlsSheet[i, 11 + j].Style = xlstStyle0;
                xlsSheet[i, 12 + j].Style = xlstStyle0;
                xlsSheet[i, 14 + j].Style = xlstStyle0;
                xlsSheet[i, 16 + j].Style = xlstStyle0;
                xlsSheet[i, 18 + j].Style = xlstStyle0;
                xlsSheet[i, j + 20].Style = xlstStyle0;
                xlsSheet[i, j + 22].Style = xlstStyle0;
                xlsSheet[i, j + 24].Style = xlstStyle0;
                xlsSheet[i, j + 26].Style = xlstStyle0;
                xlsSheet[i, j + 27].Style = xlstStyle0;
                xlsSheet[i, j + 28].Style = xlstStyle0;
                xlsSheet[i, j + 30].Style = xlstStyle0;
                xlsSheet[i, j + 32].Style = xlstStyle0;
                xlsSheet[i, j + 34].Style = xlstStyle0;
                xlsSheet[i, j + 36].Style = xlstStyle0;

                i++;
            }
            xlsSheet[i, 3 + j].Value = AllSumUsd[0];
            xlsSheet[i, 4 + j].Value = AllSumVnd[0];

            xlsSheet[i, 5 + j].Value = AllSumUsd[1];
            xlsSheet[i, 6 + j].Value = AllSumVnd[1];

            xlsSheet[i, 7 + j].Value = AllSumUsd[2];
            xlsSheet[i, 8 + j].Value = AllSumVnd[2];

            xlsSheet[i, 9 + j].Value = AllSumUsd[3];
            xlsSheet[i, 10 + j].Value = AllSumVnd[3];

            xlsSheet[i, 11 + j].Value = AllSumVnd[4];

            xlsSheet[i, 12 + j].Value = AllSumVnd[5];

            xlsSheet[i, 13 + j].Value = AllSumUsd[6];
            xlsSheet[i, 14 + j].Value = AllSumVnd[6];

            xlsSheet[i, 15 + j].Value = AllSumUsd[7];
            xlsSheet[i, 16 + j].Value = AllSumVnd[7];

            xlsSheet[i, 17 + j].Value = AllSumUsd[8];
            xlsSheet[i, 18 + j].Value = AllSumVnd[8];

            //-----------------------							                //-----------------------
            xlsSheet[i, j + 19].Value = AllSumUsd[9];
            xlsSheet[i, j + 20].Value = AllSumVnd[9];

            xlsSheet[i, j + 21].Value = AllSumUsd[10];
            xlsSheet[i, j + 22].Value = AllSumVnd[10];

            xlsSheet[i, j + 23].Value = AllSumUsd[11];
            xlsSheet[i, j + 24].Value = AllSumVnd[11];

            xlsSheet[i, j + 25].Value = AllSumUsd[12];
            xlsSheet[i, j + 26].Value = AllSumVnd[12];

            xlsSheet[i, j + 27].Value = AllSumVnd[13];

            xlsSheet[i, j + 28].Value = AllSumVnd[14];

            xlsSheet[i, j + 29].Value = AllSumUsd[15];
            xlsSheet[i, j + 30].Value = AllSumVnd[15];

            xlsSheet[i, j + 31].Value = AllSumUsd[16];
            xlsSheet[i, j + 32].Value = AllSumVnd[16];

            xlsSheet[i, j + 33].Value = AllSumUsd[17];
            xlsSheet[i, j + 34].Value = AllSumVnd[17];

            xlsSheet[i, j + 35].Value = AllSumUsd[18];
            xlsSheet[i, j + 36].Value = AllSumVnd[18];

            XLCellRange mrCell = new XLCellRange(i, i, 1, 3);
            xlsSheet.MergedCells.Add(mrCell);
            xlsSheet[i, 1].Value = "Tổng Cộng";

            for (int m = 0; m < 37; m++)
            {
                xlsSheet[i, m + j].Style = xlstStyleB1;
            }

            /////////////////////////////////////////
            xlsSheet[i, 4 + j].Style = xlstStyleB0;
            xlsSheet[i, 6 + j].Style = xlstStyleB0;
            xlsSheet[i, 8 + j].Style = xlstStyleB0;
            xlsSheet[i, 10 + j].Style = xlstStyleB0;
            xlsSheet[i, 11 + j].Style = xlstStyleB0;
            xlsSheet[i, 12 + j].Style = xlstStyleB0;
            xlsSheet[i, 14 + j].Style = xlstStyleB0;
            xlsSheet[i, 16 + j].Style = xlstStyleB0;
            xlsSheet[i, 18 + j].Style = xlstStyleB0;
            xlsSheet[i, j + 20].Style = xlstStyleB0;
            xlsSheet[i, j + 22].Style = xlstStyleB0;
            xlsSheet[i, j + 24].Style = xlstStyleB0;
            xlsSheet[i, j + 26].Style = xlstStyleB0;
            xlsSheet[i, j + 27].Style = xlstStyleB0;
            xlsSheet[i, j + 28].Style = xlstStyleB0;
            xlsSheet[i, j + 30].Style = xlstStyleB0;
            xlsSheet[i, j + 32].Style = xlstStyleB0;
            xlsSheet[i, j + 34].Style = xlstStyleB0;
            xlsSheet[i, j + 36].Style = xlstStyleB0;
            /////////////////////////////////////////
            XLSheet source = xlbBook.Sheets["tpl"];

            for (int row = 2; row <= 4; row++)
            {
                for (int col = 1; col <= 17; col++)
                {
                    xlsSheet[row, col].Style = source[row, col].Style;
                    xlsSheet[row, col].Value = source[row, col].Value;
                }
            }

            for (int row = 6; row <= 8; row++)
            {
                for (int col = 4; col <= 23; col++)
                {
                    xlsSheet[row - 4, col + 14].Style = source[row, col].Style;
                    xlsSheet[row - 4, col + 14].Value = source[row, col].Value;
                }
            }

            mrCell = new XLCellRange(2, 4, 1, 1);
            xlsSheet.MergedCells.Add(mrCell);

            mrCell = new XLCellRange(2, 4, 2, 2);
            xlsSheet.MergedCells.Add(mrCell);

            mrCell = new XLCellRange(2, 4, 3, 3);
            xlsSheet.MergedCells.Add(mrCell);

            mrCell = new XLCellRange(2, 2, 4, 17);
            xlsSheet.MergedCells.Add(mrCell);

            mrCell = new XLCellRange(2, 2, 20, 33);
            xlsSheet.MergedCells.Add(mrCell);

            for (int m = 0; m < 17; m++)
            {
                mrCell = new XLCellRange(3, 3, 4 + m, 5 + m);
                xlsSheet.MergedCells.Add(mrCell);

                mrCell = new XLCellRange(3, 3, 6 + m, 7 + m);
                xlsSheet.MergedCells.Add(mrCell);

                mrCell = new XLCellRange(3, 3, 8 + m, 9 + m);
                xlsSheet.MergedCells.Add(mrCell);

                mrCell = new XLCellRange(3, 3, 10 + m, 11 + m);
                xlsSheet.MergedCells.Add(mrCell);

                mrCell = new XLCellRange(3, 3, 14 + m, 15 + m);
                xlsSheet.MergedCells.Add(mrCell);

                mrCell = new XLCellRange(3, 3, 16 + m, 17 + m);
                xlsSheet.MergedCells.Add(mrCell);

                mrCell = new XLCellRange(2, 3, 18 + m, 19 + m);
                xlsSheet.MergedCells.Add(mrCell);

                mrCell = new XLCellRange(2, 3, 20 + m, 21 + m);
                xlsSheet.MergedCells.Add(mrCell);

                m += 15;
            }

            xlbBook.Save(fileNameDes);
            ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true);
        }
Exemplo n.º 34
0
        protected void btnExport_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            string sql = string.Empty;

            sql = " SELECT *";
            sql += " FROM v_BuildingTechStatusInfo";
            sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and StatusDate >= '"+ Func.FormatYYYYmmdd(txtFromDate.Text.Substring(0,10))   +"' and StatusDate <= '"+ Func.FormatYYYYmmdd(txtToDate.Text.Substring(0,10))   +"'";

            using (SqlDatabase db = new SqlDatabase())
            {
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    db.Close();

                    if (ds != null)
                    {
                        C1XLBook xlbBook = new C1XLBook();
                        string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\SuCoKyThuat.xls");
                        if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\SuCoKyThuat"))
                        {
                            Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\SuCoKyThuat"));
                        }
                        string strDT = DateTime.Now.ToString("yyyyMMddHHmmss");
                        string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\SuCoKyThuat\SuCoKyThuat" + strDT + ".xls";
                        string strFilePathExport = "Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/SuCoKyThuat/SuCoKyThuat" + strDT + ".xls";

                        string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath);
                        File.Copy(fileName, fileNameDes);

                        xlbBook.Load(fileNameDes);
                        XLSheet xlsSheet = xlbBook.Sheets["SuCoKyThuat"];

                        int i = 3;
                        XLCellRange mrCell = new XLCellRange(0, 0, 0, 2);
                        xlsSheet.MergedCells.Add(mrCell);

                        XLStyle xlstStyle = new XLStyle(xlbBook);
                        xlstStyle.AlignHorz = XLAlignHorzEnum.Left;
                        xlstStyle.AlignVert = XLAlignVertEnum.Top;
                        xlstStyle.WordWrap = true;
                        xlstStyle.Font = new Font("", 8, FontStyle.Regular);
                        xlstStyle.SetBorderColor(Color.Black);
                        xlstStyle.BorderBottom = XLLineStyleEnum.Thin;
                        xlstStyle.BorderTop = XLLineStyleEnum.Thin;
                        xlstStyle.BorderLeft = XLLineStyleEnum.Thin;
                        xlstStyle.BorderRight = XLLineStyleEnum.Thin;

                        XLStyle xlstStyle01 = new XLStyle(xlbBook);
                        xlstStyle01.AlignHorz = XLAlignHorzEnum.Center;
                        xlstStyle01.AlignVert = XLAlignVertEnum.Top;
                        xlstStyle01.WordWrap = true;
                        xlstStyle01.Font = new Font("", 8, FontStyle.Regular);
                        xlstStyle01.SetBorderColor(Color.Black);
                        xlstStyle01.BorderBottom = XLLineStyleEnum.Thin;
                        xlstStyle01.BorderTop = XLLineStyleEnum.Thin;
                        xlstStyle01.BorderLeft = XLLineStyleEnum.Thin;
                        xlstStyle01.BorderRight = XLLineStyleEnum.Thin;

                        xlsSheet[0, 0].Value = xlsSheet[0, 0].Value.ToString().Replace("{%BUILDING%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'"));
                        xlsSheet[1, 0].Value = xlsSheet[1, 0].Value.ToString().Replace("{%TU_NGAY%}", txtFromDate.Text);
                        xlsSheet[1, 0].Value = xlsSheet[1, 0].Value.ToString().Replace("{%DEN_NGAY%}", txtToDate.Text);

                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            string col01 = Func.FormatDMY(rowType[0].ToString());
                            string col02 = rowType[1].ToString();
                            string col03 = rowType[2].ToString();
                            string col04 = rowType[3].ToString();
                            string col05 = rowType[4].ToString();
                            string col06 = rowType[5].ToString();
                            string col07 = rowType[6].ToString();
                            string col08 = rowType[7].ToString();
                            string col09 = rowType[8].ToString();
                            string col10 = rowType[9].ToString();
                            string col11 = rowType[10].ToString();
                            string col12 = rowType[11].ToString();

                            xlsSheet[i, 0].Value = col01;
                            xlsSheet[i, 1].Value = col02;
                            xlsSheet[i, 2].Value = col03;
                            xlsSheet[i, 3].Value = col04;
                            xlsSheet[i, 4].Value = col05;
                            xlsSheet[i, 5].Value = col06;
                            xlsSheet[i, 6].Value = col07;
                            xlsSheet[i, 7].Value = col08;
                            xlsSheet[i, 8].Value = col09;
                            xlsSheet[i, 9].Value = col10;
                            xlsSheet[i, 10].Value = col11;

                            xlsSheet[i, 0].Style = xlstStyle01;
                            xlsSheet[i, 1].Style = xlstStyle;
                            xlsSheet[i, 2].Style = xlstStyle;
                            xlsSheet[i, 3].Style = xlstStyle;
                            xlsSheet[i, 4].Style = xlstStyle;
                            xlsSheet[i, 5].Style = xlstStyle;
                            xlsSheet[i, 6].Style = xlstStyle;
                            xlsSheet[i, 7].Style = xlstStyle;
                            xlsSheet[i, 8].Style = xlstStyle;
                            xlsSheet[i, 9].Style = xlstStyle;
                            xlsSheet[i, 10].Style = xlstStyle;
                            ++i;
                        }
                        xlbBook.Save(fileNameDes);
                        ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true);

                    }
                }
            }
        }
Exemplo n.º 35
0
        protected void btnExport_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            string sql = string.Empty;
            C1XLBook xlbBook = new C1XLBook();
            string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\GuixeThang.xlsx");
            if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\GuixeThang"))
            {
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\GuixeThang"));
            }

            string strDT = DateTime.Now.ToString("yyyyMMddHHmmss");
            string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\GuixeThang\GuiXeThang" + strDT + ".xlsx";
            string strFilePathExport = "Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/GuixeThang/GuiXeThang" + strDT + ".xlsx";

            string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath);

            File.Copy(fileName, fileNameDes);

            xlbBook.Load(fileNameDes);

            sql = " SELECT *";
            sql += " FROM v_GuiXeThang";
            sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' ";
            sql += " AND substring(NgayGui,1,6) <= '" + drpYear.SelectedValue + drpMonth.SelectedValue + "' AND ((NgayKetThuc is null) OR ";
            sql += "      (NgayKetThuc is not null and rtrim(LTRIM(NgayKetThuc)) <> '' and substring(NgayKetThuc,1,6) >= '" + drpYear.SelectedValue + drpMonth.SelectedValue + "')) Order by CustomerId";

            string[] sheetName = { "Oto", "XeMay", "XeDap", "Oto_HetHD", "XeMay_HetHD", "XeDap_HetHD" };
            int[] lines = { 4, 4, 4, 4, 4, 4 };

            using (SqlDatabase db = new SqlDatabase())
            {
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    db.Close();

                    if (ds != null)
                    {
                        int i = 4;
                        XLCellRange mrCell = new XLCellRange(0, 0, 0, 2);

                        XLStyle xlstStyle = new XLStyle(xlbBook);
                        //xlstStyle.AlignHorz = XLAlignHorzEnum.Left;
                        xlstStyle.AlignVert = XLAlignVertEnum.Top;
                        xlstStyle.WordWrap = true;
                        xlstStyle.Font = new Font("", 8, FontStyle.Regular);
                        xlstStyle.SetBorderColor(Color.Black);
                        xlstStyle.BorderBottom = XLLineStyleEnum.Thin;
                        xlstStyle.BorderTop = XLLineStyleEnum.Thin;
                        xlstStyle.BorderLeft = XLLineStyleEnum.Thin;
                        xlstStyle.BorderRight = XLLineStyleEnum.Thin;
                        xlstStyle.Format = "#,##0.00_);(#,##0.00)";

                        XLStyle xlstStyle01 = new XLStyle(xlbBook);
                        xlstStyle01.AlignHorz = XLAlignHorzEnum.Center;
                        xlstStyle01.AlignVert = XLAlignVertEnum.Top;
                        xlstStyle01.WordWrap = true;
                        xlstStyle01.Font = new Font("", 8, FontStyle.Regular);
                        xlstStyle01.SetBorderColor(Color.Black);
                        xlstStyle01.BorderBottom = XLLineStyleEnum.Thin;
                        xlstStyle01.BorderTop = XLLineStyleEnum.Thin;
                        xlstStyle01.BorderLeft = XLLineStyleEnum.Thin;
                        xlstStyle01.BorderRight = XLLineStyleEnum.Thin;

                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            XLSheet xlsSheet = xlbBook.Sheets[sheetName[Func.ParseInt(rowType[10]) - 1]];

                            string col01 = rowType[0].ToString();
                            string col02 = rowType[1].ToString();
                            string col03 = rowType[2].ToString();
                            string col04 = rowType[3].ToString();
                            string col05 = rowType[4].ToString();
                            string col06 = rowType[5].ToString();
                            string col07 = Func.FormatDMY(rowType[6].ToString());
                            string col08 = Func.FormatDMY(rowType[7].ToString());
                            string col09 = rowType[8].ToString();

                            i = lines[Func.ParseInt(rowType[10]) - 1];

                            xlsSheet[i, 0].Value = i - 3;
                            xlsSheet[i, 1].Value = col03;
                            xlsSheet[i, 2].Value = col04;
                            xlsSheet[i, 3].Value = col05;
                            xlsSheet[i, 4].Value = col06;
                            xlsSheet[i, 5].Value = col07;
                            xlsSheet[i, 6].Value = col08;
                            xlsSheet[i, 7].Value = col09;

                            xlsSheet[i, 0].Style = xlstStyle01;
                            xlsSheet[i, 1].Style = xlstStyle;
                            xlsSheet[i, 2].Style = xlstStyle;
                            xlsSheet[i, 3].Style = xlstStyle01;
                            xlsSheet[i, 4].Style = xlstStyle;
                            xlsSheet[i, 5].Style = xlstStyle01;
                            xlsSheet[i, 6].Style = xlstStyle01;
                            xlsSheet[i, 7].Style = xlstStyle;
                            //++i;
                            lines[Func.ParseInt(rowType[10]) - 1]++;
                        }
                    }

                }
            }
            ///////////////////////////////////////
            sql = " SELECT *";
            sql += " FROM v_GuiXeThang";
            sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' ";
            sql += " AND ((substring(NgayGui,1,6) > '" + drpYear.SelectedValue + drpMonth.SelectedValue + "') OR ";
            sql += "      (NgayKetThuc is not null and rtrim(LTRIM(NgayKetThuc)) <> '' and substring(NgayKetThuc,1,6) < '" + drpYear.SelectedValue + drpMonth.SelectedValue + "')) Order by CustomerId";

            ds = new DataSet();
            using (SqlDatabase db = new SqlDatabase())
            {
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    db.Close();

                    if (ds != null)
                    {
                        int i = 4;
                        XLCellRange mrCell = new XLCellRange(0, 0, 0, 2);
                        //xlsSheet.MergedCells.Add(mrCell);

                        XLStyle xlstStyle = new XLStyle(xlbBook);
                        //xlstStyle.AlignHorz = XLAlignHorzEnum.Left;
                        xlstStyle.AlignVert = XLAlignVertEnum.Top;
                        xlstStyle.WordWrap = true;
                        xlstStyle.Font = new Font("", 8, FontStyle.Regular);
                        xlstStyle.SetBorderColor(Color.Black);
                        xlstStyle.BorderBottom = XLLineStyleEnum.Thin;
                        xlstStyle.BorderTop = XLLineStyleEnum.Thin;
                        xlstStyle.BorderLeft = XLLineStyleEnum.Thin;
                        xlstStyle.BorderRight = XLLineStyleEnum.Thin;
                        xlstStyle.Format = "#,##0.00_);(#,##0.00)";

                        XLStyle xlstStyle01 = new XLStyle(xlbBook);
                        xlstStyle01.AlignHorz = XLAlignHorzEnum.Center;
                        xlstStyle01.AlignVert = XLAlignVertEnum.Top;
                        xlstStyle01.WordWrap = true;
                        xlstStyle01.Font = new Font("", 8, FontStyle.Regular);
                        xlstStyle01.SetBorderColor(Color.Black);
                        xlstStyle01.BorderBottom = XLLineStyleEnum.Thin;
                        xlstStyle01.BorderTop = XLLineStyleEnum.Thin;
                        xlstStyle01.BorderLeft = XLLineStyleEnum.Thin;
                        xlstStyle01.BorderRight = XLLineStyleEnum.Thin;

                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            XLSheet xlsSheet = xlbBook.Sheets[sheetName[Func.ParseInt(rowType[10]) + 2]];

                            string col01 = rowType[0].ToString();
                            string col02 = rowType[1].ToString();
                            string col03 = rowType[2].ToString();
                            string col04 = rowType[3].ToString();
                            string col05 = rowType[4].ToString();
                            string col06 = rowType[5].ToString();
                            string col07 = Func.FormatDMY(rowType[6].ToString());
                            string col08 = Func.FormatDMY(rowType[7].ToString());
                            string col09 = rowType[8].ToString();

                            i = lines[Func.ParseInt(rowType[10]) + 2];

                            xlsSheet[i, 0].Value = i - 3;
                            xlsSheet[i, 1].Value = col03;
                            xlsSheet[i, 2].Value = col04;
                            xlsSheet[i, 3].Value = col05;
                            xlsSheet[i, 4].Value = col06;
                            xlsSheet[i, 5].Value = col07;
                            xlsSheet[i, 6].Value = col08;
                            xlsSheet[i, 7].Value = col09;

                            xlsSheet[i, 0].Style = xlstStyle01;
                            xlsSheet[i, 1].Style = xlstStyle;
                            xlsSheet[i, 2].Style = xlstStyle;
                            xlsSheet[i, 3].Style = xlstStyle01;
                            xlsSheet[i, 4].Style = xlstStyle;
                            xlsSheet[i, 5].Style = xlstStyle01;
                            xlsSheet[i, 6].Style = xlstStyle01;
                            xlsSheet[i, 7].Style = xlstStyle;
                            lines[Func.ParseInt(rowType[10]) + 2]++;
                        }
                    }

                }
            }
            ///////////////////////////////////////

            XLSheet sheet = xlbBook.Sheets["OTo"];
            sheet[1, 0].Value = sheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'"));
            sheet[0, 0].Value = sheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue);

            sheet = xlbBook.Sheets["OTo"];
            sheet[1, 0].Value = sheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'"));
            sheet[0, 0].Value = sheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue);

            sheet = xlbBook.Sheets["OTo"];
            sheet[1, 0].Value = sheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'"));
            sheet[0, 0].Value = sheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue);

            sheet = xlbBook.Sheets["OTo"];
            sheet[1, 0].Value = sheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'"));
            sheet[0, 0].Value = sheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue);

            sheet = xlbBook.Sheets["OTo"];
            sheet[1, 0].Value = sheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'"));
            sheet[0, 0].Value = sheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue);

            sheet = xlbBook.Sheets["XeMay"];
            sheet[1, 0].Value = sheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'"));
            sheet[0, 0].Value = sheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue);

            sheet = xlbBook.Sheets["XeDap"];
            sheet[1, 0].Value = sheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'"));
            sheet[0, 0].Value = sheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue);

            sheet = xlbBook.Sheets["OTo_HetHD"];
            sheet[1, 0].Value = sheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'"));
            sheet[0, 0].Value = sheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue);

            sheet = xlbBook.Sheets["XeMay_HetHD"];
            sheet[1, 0].Value = sheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'"));
            sheet[0, 0].Value = sheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue);

            sheet = xlbBook.Sheets["XeDap_HetHD"];
            sheet[1, 0].Value = sheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'"));
            sheet[0, 0].Value = sheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue);
            xlbBook.Save(fileNameDes);
            ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true);
        }
Exemplo n.º 36
0
 public void setStyle(int row, int col, XLStyle style)
 {
     xlsSheet[row, col].Style = style;
     xlsSheetEn[row, col].Style = style;
 }
Exemplo n.º 37
0
        protected void btnExport_Click(object sender, EventArgs e)
        {
            string building = Func.ParseString(Session["__BUILDINGID__"]);

            DbHelper.ExecuteNonQuery("Delete from BD_PaymentReportMonth Where BuildingId = '" + building + "' and substring(yearmonth,1,4) = '" + DateTime.Now.Year.ToString() + "'");

            DataTable dtTable = new DataTable();
            dtTable.Columns.Add("YearMonth", Type.GetType("System.String"));
            dtTable.Columns.Add("BuildingId", Type.GetType("System.String"));
            dtTable.Columns.Add("PaymentType", Type.GetType("System.String"));
            dtTable.Columns.Add("PaymentId", Type.GetType("System.String"));
            dtTable.Columns.Add("colNo", Type.GetType("System.String"));
            dtTable.Columns.Add("ItemLevel", Type.GetType("System.String"));
            dtTable.Columns.Add("ParentId", Type.GetType("System.String"));

            string buildingId = Func.ParseString(Session["__BUILDINGID__"]);
            string sqlTmp = "Select Name,id,ParentId,ItemLevel from BD_PaymentType Where delflag = '0' and BuildingId = '" + buildingId + "' ";
            sqlTmp += "Union ";
            sqlTmp += "Select Name,id,ParentId,ItemLevel from Mst_PaymentType";

            DataTable dt = DbHelper.GetDataTable("Select * from (" + sqlTmp + ") A order by id");
            foreach (DataRow dr in dt.Rows)
            {
                if (dr["ParentId"].ToString() == "")
                {
                    int j = 1;
                    ListItem item = new ListItem();
                    item.Text = dr["Name"].ToString();
                    item.Value = dr["Id"].ToString();

                    for (int k = 0; k < 13; k++)
                    {
                        string month = Func.ParseString(k).PadLeft(2, '0');
                        string yearmonthTmp = DateTime.Now.Year.ToString() + month;
                        dtTable.Rows.Add(yearmonthTmp, building, item.Text, item.Value, k, dr["ItemLevel"].ToString(), dr["ParentId"].ToString());
                    }

                    GetChildItems(dr["Id"].ToString(), dt, dtTable, j);
                }
            }
            using (SqlBulkCopy copy = new SqlBulkCopy(Gnt.Configuration.ApplicationConfiguration.ConnectionString))
            {
                copy.DestinationTableName = "BD_PaymentReportMonth";
                copy.BatchSize = 3000;
                copy.BulkCopyTimeout = 99999;
                copy.ColumnMappings.Add(0, "YearMonth");
                copy.ColumnMappings.Add(1, "BuildingId");
                copy.ColumnMappings.Add(2, "PaymentType");
                copy.ColumnMappings.Add(3, "PaymentId");
                copy.ColumnMappings.Add(4, "colNo");
                copy.ColumnMappings.Add(5, "ItemLevel");
                copy.ColumnMappings.Add(6, "ParentId");

                copy.WriteToServer(dtTable);
            }
            using (SqlConnection con = new SqlConnection(Gnt.Configuration.ApplicationConfiguration.ConnectionString))
            {
                con.Open();
                using (SqlCommand cm = new SqlCommand("sp_PaymentMonthReport", con))
                {
                    try
                    {
                        cm.CommandType = CommandType.StoredProcedure;
                        cm.Parameters.AddWithValue("@BuildingId", building);
                        cm.Parameters.AddWithValue("@Year", drpYear.SelectedValue);

                        cm.Parameters.AddWithValue("@Created", DateTime.Now.ToString("yyyyMMddHHmmss"));
                        cm.Parameters.AddWithValue("@CreatedBy", Page.User.Identity.Name);
                        cm.Parameters.AddWithValue("@Modified", DateTime.Now.ToString("yyyyMMddHHmmss"));
                        cm.Parameters.AddWithValue("@ModifiedBy", Page.User.Identity.Name);

                        cm.CommandTimeout = 9999;

                        int ret = cm.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        ApplicationLog.WriteError(ex);
                    }
                    finally
                    {
                        con.Close();
                    }
                }
            }
            DataSet ds = new DataSet();
            string sql = string.Empty;

            sql = " SELECT id,YearMonth,BuildingId,PaymentType,isnull(InVND,0) InVND,isnull(InUSD,0) InUSD,isnull(OutVND,0) OutVND,isnull(OutUSD,0) OutUSD,Created,CreatedBy,Modified,ModifiedBy,PaymentId,colNo,bold,ItemLevel,ParentId";
            sql += " FROM BD_PaymentReportMonth ";
            sql += " WHERE BuildingId = '" + building + "' ";
            sql += " order by yearmonth, id";

            using (SqlDatabase db = new SqlDatabase())
            {
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    if (ds != null)
                    {
                        C1XLBook xlbBook = new C1XLBook();

                        string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\BaoCaoThuChiThang.xlsx");
                        if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BaoCaoThuChiThang"))
                        {
                            Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BaoCaoThuChiThang"));
                        }

                        string strDT = DateTime.Now.ToString("yyyyMMddHHmmss");
                        string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BaoCaoThuChiThang\BaoCaoThuChiThang" + strDT + ".xlsx";
                        string strFilePathExport = "Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/BaoCaoThuChiThang/BaoCaoThuChiThang" + strDT + ".xlsx";

                        string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath);

                        File.Copy(fileName, fileNameDes);

                        xlbBook.Load(fileNameDes);

                        string sheet = "BaoCao";

                        XLSheet xlsSheet = xlbBook.Sheets[sheet];

                        xlsSheet[0, 2].Value = xlsSheet[0, 2].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + building + "'"));
                        xlsSheet[0, 2].Value = xlsSheet[0, 2].Value.ToString().Replace("{%NAM_THANG%}", "NĂM " + drpYear.SelectedValue);

                        int k = 5;
                        int colData = 6;
                        string bsId = "";
                        string[] alpha = "A. B. C. D. E. F. G. H. I. J. K. L. M. N. O. P. Q. R. S. T. U. V. W. X. Y. Z.".Split(' ');
                        string[] alphaLevel2 = "I. II. III. IV. V. VI. VII. VIII. IX. X. XI. XII. XII. XIV.".Split(' ');
                        string[] alphaLevel3 = "1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20.".Split(' ');
                        string[] alphaLevel4 = "a. b. c. d. e. f. g. h. i. j. k. l. m. n. o. p. q. r. s. t. u. v. w.".Split(' ');
                        int level1 = -1;
                        int level2 = -1;
                        int level3 = -1;
                        int level4 = -1;
                        xlsSheet.Columns[1].Width = 300;
                        xlsSheet.Columns[2].Width = 300;
                        xlsSheet.Columns[3].Width = 300;
                        xlsSheet.Columns[4].Width = 300;
                        xlsSheet.Columns[5].Width = 300;

                        int lastrow = 0;
                        decimal inSumVND = 0;
                        decimal outSumVND = 0;

                        DataTable dtReport = ds.Tables[0];
                        foreach (DataRow rowType in dtReport.Rows)
                        {
                            string PaymentType = rowType["PaymentType"].ToString();
                            //string InVND = rowType["InVND"].ToString();
                            //string InUSD = rowType["InUSD"].ToString();
                            //string OutVND = rowType["OutVND"].ToString();
                            //string OutUSD = rowType["OutUSD"].ToString();
                            string PaymentId = rowType["PaymentId"].ToString();
                            int colNo = Func.ParseInt(rowType["colNo"].ToString());
                            string id = rowType["yearmonth"].ToString();
                            string ParentId = rowType["ParentId"].ToString();
                            string itemLevel = rowType["ItemLevel"].ToString();
                            //string PaymentId = rowType["PaymentId"].ToString();
                            //xlsSheet[2, j].Value = id;
                            //xlsSheet[3, j].Value = Budget;
                            //j += 2;
                            XLStyle xlstStyleAll = new XLStyle(xlbBook);
                            xlstStyleAll.WordWrap = false;
                            xlstStyleAll.Font = new Font("", 8, FontStyle.Regular);
                            xlstStyleAll.SetBorderColor(Color.Black);
                            xlstStyleAll.BorderBottom = XLLineStyleEnum.Thin;
                            xlstStyleAll.BorderTop = XLLineStyleEnum.Thin;
                            xlstStyleAll.BorderLeft = XLLineStyleEnum.Thin;
                            xlstStyleAll.BorderRight = XLLineStyleEnum.Thin;
                            xlstStyleAll.Format = "#,##0.00_);(#,##0.00)";

                            XLStyle xlstStyleLeft = new XLStyle(xlbBook);
                            xlstStyleLeft.WordWrap = false;
                            xlstStyleLeft.Font = new Font("", 8, FontStyle.Regular);
                            xlstStyleLeft.SetBorderColor(Color.Black);
                            xlstStyleLeft.BorderBottom = XLLineStyleEnum.Thin;
                            xlstStyleLeft.BorderTop = XLLineStyleEnum.Thin;
                            xlstStyleLeft.BorderLeft = XLLineStyleEnum.Thin;
                            xlstStyleLeft.Format = "#,##0.00_);(#,##0.00)";

                            XLStyle xlstStyleRight = new XLStyle(xlbBook);
                            xlstStyleRight.WordWrap = false;
                            xlstStyleRight.Font = new Font("", 8, FontStyle.Regular);
                            xlstStyleRight.SetBorderColor(Color.Black);
                            xlstStyleRight.BorderBottom = XLLineStyleEnum.Thin;
                            xlstStyleRight.BorderTop = XLLineStyleEnum.Thin;
                            xlstStyleRight.BorderRight = XLLineStyleEnum.Thin;
                            xlstStyleRight.Format = "#,##0.00_);(#,##0.00)";

                            XLStyle xlstStyleMiddle = new XLStyle(xlbBook);
                            xlstStyleMiddle.WordWrap = false;
                            xlstStyleMiddle.Font = new Font("", 8, FontStyle.Regular);
                            xlstStyleMiddle.SetBorderColor(Color.Black);
                            xlstStyleMiddle.BorderBottom = XLLineStyleEnum.Thin;
                            xlstStyleMiddle.BorderTop = XLLineStyleEnum.Thin;
                            xlstStyleMiddle.Format = "#,##0.00_);(#,##0.00)";

                            xlsSheet[k, 2].Style = xlstStyleLeft;
                            xlsSheet[k, 3].Style = xlstStyleMiddle;
                            xlsSheet[k, 4].Style = xlstStyleMiddle;
                            xlsSheet[k, 5].Style = xlstStyleMiddle;
                            xlsSheet[k, 6].Style = xlstStyleRight;

                            if (itemLevel.Equals("0"))
                            {
                                xlstStyleAll.BackColor = Color.Orange;
                                xlstStyleLeft.BackColor = Color.Orange;
                                xlstStyleRight.BackColor = Color.Orange;
                                xlstStyleMiddle.BackColor = Color.Orange;
                            }
                            else
                            {
                                xlstStyleAll.BackColor = Color.White;
                                xlstStyleLeft.BackColor = Color.White;
                                xlstStyleRight.BackColor = Color.White;
                                xlstStyleMiddle.BackColor = Color.White;
                            }

                            if (itemLevel.Equals("0") || itemLevel.Equals("1") || itemLevel.Equals("2"))
                            {
                                xlstStyleAll.Font = new Font("", 8, FontStyle.Bold);
                                xlstStyleLeft.Font = new Font("", 8, FontStyle.Bold);
                                xlstStyleRight.Font = new Font("", 8, FontStyle.Bold);
                                xlstStyleMiddle.Font = new Font("", 8, FontStyle.Bold);
                            }
                            xlsSheet[k, colData].Style = xlstStyleAll;

                            if (!bsId.Equals(id))
                            {
                                if (k > 5)
                                {
                                    lastrow = k;
                                    xlsSheet[k, 2].Value = alpha[level1 + 1];
                                    xlsSheet[k, 3].Value = "CÂN ĐỐI THU - CHI (Phần Lãi)";
                                    xlsSheet[k, colData].Value = Func.ParseDouble(inSumVND - outSumVND);
                                }

                                k = 5;
                                colData++;
                                bsId = id;
                                level1 = -1;
                            }
                            int col = Func.ParseInt(itemLevel) + 3;

                            if (itemLevel.Equals("0"))
                            {
                                level1++;
                                xlsSheet[k, col - 1].Value = alpha[level1];

                                level2 = -1;
                            }
                            else if (itemLevel.Equals("1"))
                            {
                                level2++;
                                xlsSheet[k, col - 1].Value = alphaLevel2[level2];

                                level3 = -1;
                            }
                            else if (itemLevel.Equals("2"))
                            {
                                level3++;
                                xlsSheet[k, col - 1].Value = alphaLevel3[level3];

                                level4 = -1;
                            }
                            else if (itemLevel.Equals("3"))
                            {
                                level4++;
                                xlsSheet[k, col - 1].Value = alphaLevel4[level4];
                            }
                            xlsSheet[k, col].Value = PaymentType;
                            xlsSheet[k, colData].Value = rowType["InVND"];
                            xlsSheet[k, 0].Value = PaymentId;

                            if (PaymentId.Equals("9"))
                            {
                                inSumVND = Convert.ToDecimal(rowType["InVND"]);
                            }
                            else if (PaymentId.Equals("10"))
                            {
                                outSumVND = Convert.ToDecimal(rowType["InVND"]);
                            }

                            xlsSheet[k, colData].Style = xlstStyleAll;
                            k++;

                            if (k == lastrow)
                            {
                                XLStyle xlstStyleLast = new XLStyle(xlbBook);
                                xlstStyleLast.WordWrap = false;
                                xlstStyleLast.Font = new Font("", 8, FontStyle.Regular);
                                xlstStyleLast.SetBorderColor(Color.Black);
                                xlstStyleLast.BorderBottom = XLLineStyleEnum.Thin;
                                xlstStyleLast.BorderTop = XLLineStyleEnum.Thin;
                                xlstStyleLast.BorderLeft = XLLineStyleEnum.Thin;
                                xlstStyleLast.BorderRight = XLLineStyleEnum.Thin;
                                xlstStyleLast.Font = new Font("", 8, FontStyle.Bold);
                                xlstStyleLast.BackColor = Color.Orange;
                                xlstStyleLast.Format = "#,##0.00_);(#,##0.00)";

                                xlsSheet[k, colData].Value = inSumVND - outSumVND;
                                xlsSheet[k, colData].Style = xlstStyleLast;
                            }
                        }
                        xlbBook.Save(fileNameDes);
                        ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true);
                    }
                }
            }
        }
        protected void btnExport_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            string sql = string.Empty;

            sql = " SELECT *";
            sql += " FROM Report_BuildingInfo where id = 43";

            using (SqlDatabase db = new SqlDatabase())
            {
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    if (ds != null)
                    {
                        C1XLBook xlbBook = new C1XLBook();
                        XLStyle xlstStyle = new XLStyle(xlbBook);
                        xlstStyle.AlignHorz = XLAlignHorzEnum.Center;
                        xlstStyle.WordWrap = true;
                        xlstStyle.Font = new Font("", 8, FontStyle.Regular);
                        xlstStyle.SetBorderColor(Color.Black);
                        xlstStyle.BorderBottom = XLLineStyleEnum.Thin;
                        xlstStyle.BorderTop = XLLineStyleEnum.Thin;
                        xlstStyle.BorderLeft = XLLineStyleEnum.Thin;
                        xlstStyle.BorderRight = XLLineStyleEnum.Thin;

                        string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\LamNgoaiGio.xlsx");
                        if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"])))
                        {
                            Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"])));
                        }

                        string strDT = DateTime.Now.ToString("yyyyMMddHHmmss");
                        string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\LamNgoaiGio" + strDT + ".xlsx";
                        string strFilePathExport = "Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/LamNgoaiGio" + strDT + ".xlsx";

                        string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath);

                        //string fileNameDes = HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\TongHopDienTich" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx");
                        File.Copy(fileName, fileNameDes);

                        xlbBook.Load(fileNameDes);

                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            int stt = 0;
                            string id = rowType["id"].ToString();
                            string sheet = "Report";
                            int NumOfCol = Func.ParseInt(rowType["NoOfColumn"].ToString());
                            string SqlSelect = rowType["SqlSelect"].ToString();
                            SqlSelect = SqlSelect.Replace("{%NAM_THANG%}", drpYear.SelectedValue + drpMonth.SelectedValue);

                            SqlSelect = SqlSelect.Replace("{%TOA_NHA%}", Func.ParseString(Session["__BUILDINGID__"]));
                            int CellY = Func.ParseInt(rowType["CellBeginY"].ToString());
                            int CellX = Func.ParseInt(rowType["CellBeginX"].ToString());

                            using (SqlCommand cmSheet = db.CreateCommand(SqlSelect))
                            {
                                DataSet dsSheet = new DataSet();
                                SqlDataAdapter daSheet = new SqlDataAdapter(cmSheet);
                                daSheet.Fill(dsSheet);
                                if (dsSheet != null)
                                {
                                    XLSheet xlsSheet = xlbBook.Sheets[sheet];

                                    DataTable dtSheet = dsSheet.Tables[0];
                                    foreach (DataRow rowSheet in dtSheet.Rows)
                                    {
                                        xlsSheet[CellY + stt, CellX].Style = xlstStyle;
                                        xlsSheet[CellY + stt, CellX].Value = ++stt;

                                        for (int k = 0; k < NumOfCol; k++)
                                        {
                                            //string tmp = rowSheet[k].ToString();
                                            //switch (rowSheet[k].GetType().Name)
                                            //{
                                            //    case "Decimal":
                                            //        xlsSheet[CellY + stt - 1, CellX + k + 1].Value = Func.ParseDouble(tmp);
                                            //        break;

                                            //    case "Double":
                                            //        xlsSheet[CellY + stt - 1, CellX + k + 1].Value = Func.ParseDouble(tmp);

                                            //        break;
                                            //    case "Int32":
                                            //        xlsSheet[CellY + stt - 1, CellX + k + 1].Value = Func.ParseInt(tmp);

                                            //        break;
                                            //    case "Single":
                                            //        xlsSheet[CellY + stt - 1, CellX + k + 1].Value = Func.ParseInt(tmp);
                                            //        break;
                                            //    default:
                                            //        xlsSheet[CellY + stt - 1, CellX + k + 1].Value = tmp;
                                            //        break;
                                            //}
                                            //xlsSheet[CellY + stt - 1, CellX + k + 1].Value = tmp;
                                            xlsSheet[CellY + stt - 1, CellX + k + 1].Value = rowSheet[k];

                                            xlsSheet[CellY + stt - 1, CellX + k + 1].Style = xlstStyle;
                                        }
                                    }
                                }
                            }
                            //xlsSheet.Name = drpMonth.SelectedValue + "_" + drpYear.SelectedValue;

                            //int i = 4;
                            //XLCellRange mrCell = new XLCellRange(0, 0, 0, 2);
                            //xlsSheet.MergedCells.Add(mrCell);

                            //XLStyle xlstStyle = new XLStyle(xlbBook);
                            //xlstStyle.AlignHorz = XLAlignHorzEnum.Center;
                            //xlstStyle.WordWrap = true;
                            //xlstStyle.Font = new Font("", 8, FontStyle.Regular);
                            //xlstStyle.SetBorderColor(Color.Black);
                            //xlstStyle.BorderBottom = XLLineStyleEnum.Thin;
                            //xlstStyle.BorderTop = XLLineStyleEnum.Thin;
                            //xlstStyle.BorderLeft = XLLineStyleEnum.Thin;
                            //xlstStyle.BorderRight = XLLineStyleEnum.Thin;

                            //XLStyle xlstStyle01 = new XLStyle(xlbBook);
                            //xlstStyle01.AlignHorz = XLAlignHorzEnum.Center;
                            //xlstStyle01.Font = new Font("", 10, FontStyle.Bold);
                            //xlstStyle.SetBorderColor(Color.Black);

                            //xlsSheet[1, 0].Value = xlsSheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'"));
                            //xlsSheet[0, 0].Value = xlsSheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue);

                            //xlsSheet[i, 0].Value = ++stt;
                            //xlsSheet[i, 1].Value = col03;
                            //xlsSheet[i, 2].Value = col04;
                            //xlsSheet[i, 3].Value = col05;
                            //xlsSheet[i, 4].Value = col06;
                            //xlsSheet[i, 5].Value = col07;
                            //xlsSheet[i, 6].Value = col08;
                            //xlsSheet[i, 7].Value = col09;

                            //xlsSheet[i, 0].Style = xlstStyle;
                            //xlsSheet[i, 1].Style = xlstStyle;
                            //xlsSheet[i, 2].Style = xlstStyle;
                            //xlsSheet[i, 3].Style = xlstStyle;
                            //xlsSheet[i, 4].Style = xlstStyle;
                            //xlsSheet[i, 5].Style = xlstStyle;
                            //xlsSheet[i, 6].Style = xlstStyle;
                            //xlsSheet[i, 7].Style = xlstStyle;
                            //++i;
                        }

                        ////ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('/CSV/DownloadZipFile.aspx'," + PopupWidth + "," + PopupHeight + ",'EditFlat', true);", true);

                        ////xlsSheet[i++, 0].Value = "Ghi chú:";
                        //DataSet ds1 = new DataSet();
                        //sql = string.Empty;

                        //sql = " SELECT *";
                        //sql += " FROM BD_WorkingHour";
                        //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and DelFlag <> 1";
                        //sql += " Order By Name";

                        //using (SqlCommand cm1 = db.CreateCommand(sql))
                        //{
                        //    SqlDataAdapter da1 = new SqlDataAdapter(cm1);
                        //    da1.Fill(ds1);
                        //    db.Close();

                        //    if (ds != null)
                        //    {

                        //        xlsSheet[i++ + 1, 0].Value = "Ghi chú:";
                        //        DataTable dt1 = ds1.Tables[0];
                        //        foreach (DataRow rowType in dt1.Rows)
                        //        {
                        //            i++;
                        //            string Ma = rowType["WorkingHourId"].ToString();
                        //            string Name = rowType["Name"].ToString();
                        //            xlsSheet[i, 0].Value = Ma + ":";
                        //            xlsSheet[i, 1].Value = Name;
                        //        }
                        //        xlsSheet[i + 1, 0].Value = "OF:";
                        //        xlsSheet[i + 1, 1].Value = "OF: nghỉ";
                        //    }
                        //}
                        //string dataPath = HttpContext.Current.Server.MapPath(@"\Building\Staff\DataTmp");
                        //string tmpFolder = dataPath;
                        //if (!Directory.Exists(tmpFolder))
                        //{
                        //    Directory.CreateDirectory(tmpFolder);
                        //}
                        //string name = "KhaiBaoLichLamViec_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xlsx";
                        //string fileName = Path.Combine(tmpFolder, name);
                        //                        string fileNameDes = HttpContext.Current.Server.MapPath(@"\Report\Template\THSLXT_tpl_1.xlsxx");
                        xlbBook.Save(fileNameDes);
                        ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true);

                    }
                }
            }
        }
Exemplo n.º 39
0
        protected void btnExport_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            string sql = string.Empty;

            sql = " SELECT *";
            sql += " FROM vBuildingRoomInfo";
            sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' ";

            using (SqlDatabase db = new SqlDatabase())
            {
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    db.Close();

                    string selectDate = Func.FormatYYYYmmdd(txtDate.Text);
                    if (ds != null)
                    {
                        C1XLBook xlbBook = new C1XLBook();
                        string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\TongHopDienTichTrong.xls");
                        if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"])))
                        {
                            Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"])));
                        }

                        string strDT = DateTime.Now.ToString("yyyyMMddHHmmss");
                        string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\TongHopDienTich" + strDT + ".xls";
                        string strFilePathExport = "Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/TongHopDienTich" + strDT + ".xls";

                        string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath);

                        //string fileNameDes = HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\TongHopDienTich" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
                        File.Copy(fileName, fileNameDes);

                        xlbBook.Load(fileNameDes);
                        XLSheet xlsSheet = xlbBook.Sheets["TongHop"];
                        //xlsSheet.Name = drpMonth.SelectedValue + "_" + drpYear.SelectedValue;

                        int i = 4;
                        XLCellRange mrCell = new XLCellRange(0, 0, 0, 2);
                        xlsSheet.MergedCells.Add(mrCell);

                        XLStyle xlstStyle = new XLStyle(xlbBook);
                        xlstStyle.AlignHorz = XLAlignHorzEnum.Center;
                        xlstStyle.Font = new Font("", 12, FontStyle.Bold);
                        xlstStyle.SetBorderColor(Color.Black);

                        XLStyle xlstStyle01 = new XLStyle(xlbBook);
                        xlstStyle01.AlignHorz = XLAlignHorzEnum.Center;
                        xlstStyle01.Font = new Font("", 10, FontStyle.Bold);
                        xlstStyle.SetBorderColor(Color.Black);

                        xlsSheet[1, 0].Value = xlsSheet[1, 0].Value.ToString().Replace("{%BUILDING%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'"));
                        xlsSheet[0, 0].Value = xlsSheet[0, 0].Value.ToString().Replace("{%NGAY%}", txtDate.Text);

                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            string col01 = rowType[0].ToString();
                            string col02 = rowType[1].ToString();
                            string col03 = rowType[2].ToString();
                            string col04 = rowType[3].ToString();
                            string col05 = rowType[4].ToString();
                            string col06 = rowType[5].ToString();

                            xlsSheet[i, 0].Value = col02;
                            xlsSheet[i, 1].Value = col03;
                            xlsSheet[i, 2].Value = col04;
                            xlsSheet[i, 3].Value = col05;
                            xlsSheet[i, 4].Value = DbHelper.GetScalar("Select sum(Area) from vRentRoom Where BuildingId = '" + col01 + "' and Regional ='" + col02 + "' and Floor = '" + col03 + "' and (BeginContract <= '" + selectDate + "' and (EndContract >= '" + selectDate + "' or EndContract is null))");
                            xlsSheet[i, 5].Value = col05;

                            xlsSheet[i, 0].Style = xlstStyle01;
                            xlsSheet[i, 1].Style = xlstStyle01;
                            xlsSheet[i, 2].Style = xlstStyle01;
                            ++i;
                        }

                        ////ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('/CSV/DownloadZipFile.aspx'," + PopupWidth + "," + PopupHeight + ",'EditFlat', true);", true);

                        ////xlsSheet[i++, 0].Value = "Ghi chú:";
                        //DataSet ds1 = new DataSet();
                        //sql = string.Empty;

                        //sql = " SELECT *";
                        //sql += " FROM BD_WorkingHour";
                        //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and DelFlag <> 1";
                        //sql += " Order By Name";

                        //using (SqlCommand cm1 = db.CreateCommand(sql))
                        //{
                        //    SqlDataAdapter da1 = new SqlDataAdapter(cm1);
                        //    da1.Fill(ds1);
                        //    db.Close();

                        //    if (ds != null)
                        //    {

                        //        xlsSheet[i++ + 1, 0].Value = "Ghi chú:";
                        //        DataTable dt1 = ds1.Tables[0];
                        //        foreach (DataRow rowType in dt1.Rows)
                        //        {
                        //            i++;
                        //            string Ma = rowType["WorkingHourId"].ToString();
                        //            string Name = rowType["Name"].ToString();
                        //            xlsSheet[i, 0].Value = Ma + ":";
                        //            xlsSheet[i, 1].Value = Name;
                        //        }
                        //        xlsSheet[i + 1, 0].Value = "OF:";
                        //        xlsSheet[i + 1, 1].Value = "OF: nghỉ";
                        //    }
                        //}
                        //string dataPath = HttpContext.Current.Server.MapPath(@"\Building\Staff\DataTmp");
                        //string tmpFolder = dataPath;
                        //if (!Directory.Exists(tmpFolder))
                        //{
                        //    Directory.CreateDirectory(tmpFolder);
                        //}
                        //string name = "KhaiBaoLichLamViec_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls";
                        //string fileName = Path.Combine(tmpFolder, name);
            //                        string fileNameDes = HttpContext.Current.Server.MapPath(@"\Report\Template\THSLXT_tpl_1.xlsx");

                        xlbBook.Save(fileNameDes);
                        //Session["ZipFilePath"] = null;
                        //Session["ZipFilePath"] = fileName;

                        ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true);

                    }
                }
            }
        }
        protected void btnExport_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            string sql = string.Empty;

            sql = " SELECT *";
            sql += " FROM v_GuiXeThang";
            sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' ";
            sql += " AND ((NgayKetThuc is null) OR ";
            sql += "      (NgayKetThuc is not null and substring(NgayKetThuc,1,6) >= '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'))";

            using (SqlDatabase db = new SqlDatabase())
            {
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    db.Close();

                    if (ds != null)
                    {
                        C1XLBook xlbBook = new C1XLBook();
                        string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\GuixeThang.xls");
                        if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"])))
                        {
                            Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"])));
                        }

                        string strDT = DateTime.Now.ToString("yyyyMMddHHmmss");
                        string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\GuiXeThang" + strDT + ".xls";
                        string strFilePathExport = "Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/GuiXeThang" + strDT + ".xls";

                        string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath);

                        //string fileNameDes = HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\TongHopDienTich" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
                        File.Copy(fileName, fileNameDes);

                        xlbBook.Load(fileNameDes);
                        XLSheet xlsSheet = xlbBook.Sheets["GuiXeThang"];
                        //xlsSheet.Name = drpMonth.SelectedValue + "_" + drpYear.SelectedValue;

                        int i = 4;
                        XLCellRange mrCell = new XLCellRange(0, 0, 0, 2);
                        xlsSheet.MergedCells.Add(mrCell);

                        XLStyle xlstStyle = new XLStyle(xlbBook);
                        xlstStyle.AlignHorz = XLAlignHorzEnum.Center;
                        xlstStyle.WordWrap = true;
                        xlstStyle.Font = new Font("", 8, FontStyle.Regular);
                        xlstStyle.SetBorderColor(Color.Black);
                        xlstStyle.BorderBottom = XLLineStyleEnum.Thin;
                        xlstStyle.BorderTop = XLLineStyleEnum.Thin;
                        xlstStyle.BorderLeft = XLLineStyleEnum.Thin;
                        xlstStyle.BorderRight = XLLineStyleEnum.Thin;

                        XLStyle xlstStyle01 = new XLStyle(xlbBook);
                        xlstStyle01.AlignHorz = XLAlignHorzEnum.Center;
                        xlstStyle01.Font = new Font("", 10, FontStyle.Bold);
                        xlstStyle.SetBorderColor(Color.Black);

                        xlsSheet[1, 0].Value = xlsSheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'"));
                        xlsSheet[0, 0].Value = xlsSheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue+"/"+drpYear.SelectedValue);

                        int stt = 0;
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            string col01 = rowType[0].ToString();
                            string col02 = rowType[1].ToString();
                            string col03 = rowType[2].ToString();
                            string col04 = rowType[3].ToString();
                            string col05 = rowType[4].ToString();
                            string col06 = rowType[5].ToString();
                            string col07 = Func.FormatDMY(rowType[6].ToString());
                            string col08 = Func.FormatDMY(rowType[7].ToString());
                            string col09 = rowType[8].ToString();

                            xlsSheet[i, 0].Value = ++stt;
                            xlsSheet[i, 1].Value = col03;
                            xlsSheet[i, 2].Value = col04;
                            xlsSheet[i, 3].Value = col05;
                            xlsSheet[i, 4].Value = col06;
                            xlsSheet[i, 5].Value = col07;
                            xlsSheet[i, 6].Value = col08;
                            xlsSheet[i, 7].Value = col09;

                            xlsSheet[i, 0].Style = xlstStyle;
                            xlsSheet[i, 1].Style = xlstStyle;
                            xlsSheet[i, 2].Style = xlstStyle;
                            xlsSheet[i, 3].Style = xlstStyle;
                            xlsSheet[i, 4].Style = xlstStyle;
                            xlsSheet[i, 5].Style = xlstStyle;
                            xlsSheet[i, 6].Style = xlstStyle;
                            xlsSheet[i, 7].Style = xlstStyle;
                            ++i;
                        }

                        ////ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('/CSV/DownloadZipFile.aspx'," + PopupWidth + "," + PopupHeight + ",'EditFlat', true);", true);

                        ////xlsSheet[i++, 0].Value = "Ghi chú:";
                        //DataSet ds1 = new DataSet();
                        //sql = string.Empty;

                        //sql = " SELECT *";
                        //sql += " FROM BD_WorkingHour";
                        //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and DelFlag <> 1";
                        //sql += " Order By Name";

                        //using (SqlCommand cm1 = db.CreateCommand(sql))
                        //{
                        //    SqlDataAdapter da1 = new SqlDataAdapter(cm1);
                        //    da1.Fill(ds1);
                        //    db.Close();

                        //    if (ds != null)
                        //    {

                        //        xlsSheet[i++ + 1, 0].Value = "Ghi chú:";
                        //        DataTable dt1 = ds1.Tables[0];
                        //        foreach (DataRow rowType in dt1.Rows)
                        //        {
                        //            i++;
                        //            string Ma = rowType["WorkingHourId"].ToString();
                        //            string Name = rowType["Name"].ToString();
                        //            xlsSheet[i, 0].Value = Ma + ":";
                        //            xlsSheet[i, 1].Value = Name;
                        //        }
                        //        xlsSheet[i + 1, 0].Value = "OF:";
                        //        xlsSheet[i + 1, 1].Value = "OF: nghỉ";
                        //    }
                        //}
                        //string dataPath = HttpContext.Current.Server.MapPath(@"\Building\Staff\DataTmp");
                        //string tmpFolder = dataPath;
                        //if (!Directory.Exists(tmpFolder))
                        //{
                        //    Directory.CreateDirectory(tmpFolder);
                        //}
                        //string name = "KhaiBaoLichLamViec_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls";
                        //string fileName = Path.Combine(tmpFolder, name);
            //                        string fileNameDes = HttpContext.Current.Server.MapPath(@"\Report\Template\THSLXT_tpl_1.xlsx");

                        xlbBook.Save(fileNameDes);
                        //Session["ZipFilePath"] = null;
                        //Session["ZipFilePath"] = fileName;

                        ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true);

                    }
                }
            }
        }
Exemplo n.º 41
0
        protected void btnExport_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            string sql = string.Empty;

            sql = " SELECT *";
            sql += " FROM Report_BuildingInfo where id = 42";

            using (SqlDatabase db = new SqlDatabase())
            {
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    if (ds != null)
                    {
                        C1XLBook xlbBook = new C1XLBook();
                        XLStyle xlstStyle = new XLStyle(xlbBook);
                        xlstStyle.AlignHorz = XLAlignHorzEnum.Center;
                        xlstStyle.WordWrap = true;
                        xlstStyle.Font = new Font("", 8, FontStyle.Regular);
                        xlstStyle.SetBorderColor(Color.Black);
                        xlstStyle.BorderBottom = XLLineStyleEnum.Thin;
                        xlstStyle.BorderTop = XLLineStyleEnum.Thin;
                        xlstStyle.BorderLeft = XLLineStyleEnum.Thin;
                        xlstStyle.BorderRight = XLLineStyleEnum.Thin;

                        string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\NuocTieuThuThang.xlsx");
                        if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\NuocTieuThuThang"))
                        {
                            Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\NuocTieuThuThang"));
                        }

                        string strDT = DateTime.Now.ToString("yyyyMMddHHmmss");
                        string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\NuocTieuThuThang\NuocTieuThuThang" + strDT + ".xlsx";
                        string strFilePathExport = "Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/NuocTieuThuThang/NuocTieuThuThang" + strDT + ".xlsx";

                        string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath);

                        File.Copy(fileName, fileNameDes);

                        xlbBook.Load(fileNameDes);

                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            int stt = 0;
                            string id = rowType["id"].ToString();
                            string sheet = "Report";
                            int NumOfCol = Func.ParseInt(rowType["NoOfColumn"].ToString());
                            string SqlSelect = rowType["SqlSelect"].ToString();
                            SqlSelect = SqlSelect.Replace("{%DATE_FROM%}", Func.FormatYYYYmmdd(txtFromDate.Text));
                            SqlSelect = SqlSelect.Replace("{%DATE_TO%}", Func.FormatYYYYmmdd(txtToDate.Text));
                            SqlSelect = SqlSelect.Replace("{%TOA_NHA%}", Func.ParseString(Session["__BUILDINGID__"]));

                            XLSheet xlsSheet = xlbBook.Sheets[sheet];
                            xlsSheet[0, 1].Value = xlsSheet[0, 1].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'"));
                            xlsSheet[0, 1].Value = xlsSheet[0, 1].Value.ToString().Replace("{%THANG_NAM%}", txtFromDate.Text + "~" + txtToDate.Text);

                            int CellY = Func.ParseInt(rowType["CellBeginY"].ToString());
                            int CellX = Func.ParseInt(rowType["CellBeginX"].ToString());

                            using (SqlCommand cmSheet = db.CreateCommand(SqlSelect))
                            {
                                DataSet dsSheet = new DataSet();
                                SqlDataAdapter daSheet = new SqlDataAdapter(cmSheet);
                                daSheet.Fill(dsSheet);
                                if (dsSheet != null)
                                {

                                    DataTable dtSheet = dsSheet.Tables[0];
                                    foreach (DataRow rowSheet in dtSheet.Rows)
                                    {
                                        xlsSheet[CellY + stt, CellX].Style = xlstStyle;
                                        xlsSheet[CellY + stt, CellX].Value = ++stt + "";
                                        for (int k = 0; k < NumOfCol; k++)
                                        {
                                            xlsSheet[CellY + stt - 1, CellX + k + 1].Value = rowSheet[k];
                                            xlsSheet[CellY + stt - 1, CellX + k + 1].Style = xlstStyle;
                                        }
                                    }
                                }
                            }

                        }
                        xlbBook.Save(fileNameDes);
                        ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true);

                    }
                }
            }
        }
Exemplo n.º 42
0
        public void DoExport()
        {
            int rBillNo = 0;
            int cBillNo = 1;

            int rBillDate = 0;
            int cBillDate = 10;

            int rBillMonth = 2;
            int cBillMonth = 0;

            int rContact = 5;
            int cContact = 3;

            int rCustomer = 5;
            int cCustomer = 7;

            int rContract = 7;
            int cContract = 1;

            int rRate = 11;
            int cRate = 9;

            int rRateDate = 11;
            int cRateDate = 12;

            int rRent = 15;

            int rManager = 23;

            int rParking = 31;

            int rExtra = 39;

            int rElec = 47;

            int rWater = 55;

            int rService = 63;

            int rPaid = 70;

            int rDept = 77;

            int rOffice = 88;
            int cOffice = 3;

            int rPhone = 89;
            int cPhone = 3;

            int rBank = 88;
            int cBank = 7;

            int rAccountName = 89;
            int cAccountName = 7;

            int rAccount = 90;
            int cAccount = 7;

            int rSum = 81;
            int cSum = 12;

            int rSumVND = 80;
            int cSumVND = 12;

            int rSumRead = 82;
            int cSumRead = 13;

            ////
            using (SqlDatabase db = new SqlDatabase())
            {

                DataSet ds = new DataSet();
                DataSet dsCus = new DataSet();

                string sql = string.Empty;

                string Bank = "";
                string Account = "";
                string AccountName = "";
                string Office = "";
                string OfficeAddress = "";
                string OfficePhone = "";

                ds = new DataSet();
                sql = " SELECT Bank,Account,AccountName,Office,OfficeAddress,OfficePhone";
                sql += " FROM Mst_Building";
                sql += " WHERE BuildingId = '" + sBuildingId + "' ";
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    if (ds != null)
                    {
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            Bank = rowType["Bank"].ToString();
                            Account = rowType["Account"].ToString();
                            AccountName = rowType["AccountName"].ToString();
                            Office = rowType["Office"].ToString();
                            OfficeAddress = rowType["OfficeAddress"].ToString();
                            OfficePhone = rowType["OfficePhone"].ToString();
                        }
                    }
                }

                //Danh sách Bill
                sql = "  Select BillDate,UsdExchangeDate,UsdExchange,BillNo,B.Name,B.ContactName,A.CustomerId, A.YearMonths, A.Id ";
                sql += " From	PaymentBillInfo A, Customer B";
                sql += " Where	A.BuildingId = B.BuildingId and A.CustomerId = B.CustomerId and B.DelFlag = 0 and A.BuildingId = '" + sBuildingId + "' and YearMonth = '" + sYearMonth + "'";

                string BillDate = "";
                string UsdExchangeDate = "";
                string UsdExchange = "";
                string BillNo = "";
                string Name = "";
                string ContactName = "";
                string CustomerId = "";
                string lsYearmonth = "";
                string id = "";

                string maxYearMonth = "";

                using (SqlCommand cmCus = db.CreateCommand(sql))
                {
                    SqlDataAdapter daCus = new SqlDataAdapter(cmCus);
                    daCus.Fill(dsCus);

                    if (dsCus != null)
                    {
                        string strDT = DateTime.Now.ToString("yyyyMMddHHmmss");

                        DataTable dtCus = dsCus.Tables[0];
                        foreach (DataRow rowCus in dtCus.Rows)
                        {
                            BillDate = rowCus[0].ToString();
                            UsdExchangeDate = rowCus[1].ToString();
                            UsdExchange = rowCus[2].ToString();
                            BillNo = rowCus[3].ToString();
                            Name = rowCus[4].ToString();
                            ContactName = rowCus[5].ToString();
                            CustomerId = rowCus[6].ToString();
                            lsYearmonth = rowCus[7].ToString();
                            id = rowCus[8].ToString();

                            string[] strTmpYearMonth = lsYearmonth.Split(',');

                            for (int l = 0; l < strTmpYearMonth.Length; l++)
                            {
                                string tmp = strTmpYearMonth[l];
                                if (maxYearMonth == "")
                                    maxYearMonth = tmp;
                                if (maxYearMonth.CompareTo(tmp) < 0)
                                    maxYearMonth = tmp;
                            }

                            C1XLBook xlbBook = new C1XLBook();
                            //ShowData(drpYear.SelectedValue + drpMonth.SelectedValue);
                            XLStyle xlstStyle = new XLStyle(xlbBook);
                            xlstStyle.AlignHorz = XLAlignHorzEnum.Center;
                            xlstStyle.AlignVert = XLAlignVertEnum.Center;
                            xlstStyle.WordWrap = true;
                            xlstStyle.Font = new Font("", 8, FontStyle.Regular);
                            xlstStyle.SetBorderColor(Color.Black);
                            xlstStyle.BorderBottom = XLLineStyleEnum.Thin;
                            xlstStyle.BorderTop = XLLineStyleEnum.Thin;
                            xlstStyle.BorderLeft = XLLineStyleEnum.Thin;
                            xlstStyle.BorderRight = XLLineStyleEnum.Thin;
                            xlstStyle.Format = "#,##0.00_);(#,##0.00)";

                            XLStyle xlstStyleH = new XLStyle(xlbBook);
                            xlstStyleH.AlignHorz = XLAlignHorzEnum.Center;
                            xlstStyleH.AlignVert = XLAlignVertEnum.Center;
                            xlstStyleH.Font = new Font("", 8, FontStyle.Bold);
                            xlstStyleH.SetBorderColor(Color.Black);
                            xlstStyleH.BorderBottom = XLLineStyleEnum.Thin;
                            xlstStyleH.BorderTop = XLLineStyleEnum.Thin;
                            xlstStyleH.BorderLeft = XLLineStyleEnum.Thin;
                            xlstStyleH.BorderRight = XLLineStyleEnum.Thin;
                            xlstStyleH.WordWrap = true;

                            XLStyle xlstStyleSum = new XLStyle(xlbBook);
                            xlstStyleSum.AlignHorz = XLAlignHorzEnum.Right;
                            xlstStyleSum.AlignVert = XLAlignVertEnum.Center;
                            xlstStyleSum.Font = new Font("", 8, FontStyle.Bold);
                            xlstStyleSum.SetBorderColor(Color.Black);
                            xlstStyleSum.BorderBottom = XLLineStyleEnum.Thin;
                            xlstStyleSum.BorderTop = XLLineStyleEnum.Thin;
                            xlstStyleSum.BorderLeft = XLLineStyleEnum.Thin;
                            xlstStyleSum.BorderRight = XLLineStyleEnum.Thin;
                            xlstStyleSum.WordWrap = true;

                            string fileName = sFilePath + @"\Template\BillTongQuat.xlsx";
                            if (!Directory.Exists(sFilePath + @"\Building\" + sBuildingId + @"\Bill"))
                            {
                                Directory.CreateDirectory(sFilePath + @"\Report\Building\" + sBuildingId + @"\Bill");
                            }

                            string strFilePath = sFilePath + @"\Building\" + sBuildingId + @"\Bill\Bill" + "_" + CustomerId + "_" + BillNo + id + "_" + strDT + ".xlsx";
                            string strFilePathExport = sFilePath.Replace(@"\", "/") + @"/Building/" + sBuildingId + @"/Bill/Bill" + "_" + CustomerId + "_" + BillNo + id + "_" + strDT + ".xlsx";

                            string fileNameDes = strFilePath;

                            //string fileNameDes = HttpContext.Current.Server.MapPath(@"~\Report\Building\" + sBuildingId + @"\TongHopDienTich" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
                            File.Copy(fileName, fileNameDes);

                            xlbBook.Load(fileNameDes);
                            XLSheet xlsSheet = xlbBook.Sheets["TongHop"];
                            XLSheet xlsSheetEn = xlbBook.Sheets["TongHop_En"];

                            //Thông tin về Ngân hàng của Tòa Nhà
                            xlsSheet[rOffice, cOffice].Value = xlsSheet[rOffice, cOffice].Value.ToString().Replace("{%VAN_PHONG%}", Office);
                            xlsSheet[rPhone, cPhone].Value = xlsSheet[rPhone, cPhone].Value.ToString().Replace("{%DIEN_THOAI%}", OfficePhone);

                            xlsSheet[rBank, cBank].Value = xlsSheet[rBank, cBank].Value.ToString().Replace("{%NGAN_HANG%}", Bank);
                            xlsSheet[rAccountName, cAccountName].Value = xlsSheet[rAccountName, cAccountName].Value.ToString().Replace("{%TEN_TAI_KHOAN%}", AccountName);
                            xlsSheet[rAccount, cAccount].Value = xlsSheet[rAccount, cAccount].Value.ToString().Replace("{%SO_TAI_KHOAN%}", Account);
                            //Thông tin về Ngân hàng của Tòa Nhà

                            //Customer
                            xlsSheet[rCustomer, cCustomer].Value = xlsSheet[rCustomer, cCustomer].Value.ToString().Replace("{%TEN_CONG_TY%}", Name);
                            //Contact
                            xlsSheet[rContact, cContact].Value = xlsSheet[rContact, cContact].Value.ToString().Replace("{%NGUOI_DAI_DIEN%}", ContactName);

                            //Bill No
                            xlsSheet[rBillNo, cBillNo].Value = xlsSheet[rBillNo, cBillNo].Value.ToString().Replace("{%BILL_NO%}", BillNo);

                            ///////////////////////////////////////////
                            //Thông tin về Ngân hàng của Tòa Nhà
                            xlsSheetEn[rOffice, cOffice].Value = xlsSheetEn[rOffice, cOffice].Value.ToString().Replace("{%VAN_PHONG%}", Office);
                            xlsSheetEn[rPhone, cPhone].Value = xlsSheetEn[rPhone, cPhone].Value.ToString().Replace("{%DIEN_THOAI%}", OfficePhone);

                            xlsSheetEn[rBank, cBank].Value = xlsSheetEn[rBank, cBank].Value.ToString().Replace("{%NGAN_HANG%}", Bank);
                            xlsSheetEn[rAccountName, cAccountName].Value = xlsSheetEn[rAccountName, cAccountName].Value.ToString().Replace("{%TEN_TAI_KHOAN%}", AccountName);
                            xlsSheetEn[rAccount, cAccount].Value = xlsSheetEn[rAccount, cAccount].Value.ToString().Replace("{%SO_TAI_KHOAN%}", Account);
                            //Thông tin về Ngân hàng của Tòa Nhà

                            //Customer
                            xlsSheetEn[rCustomer, cCustomer].Value = xlsSheetEn[rCustomer, cCustomer].Value.ToString().Replace("{%TEN_CONG_TY%}", Name);
                            //Contact
                            xlsSheetEn[rContact, cContact].Value = xlsSheetEn[rContact, cContact].Value.ToString().Replace("{%NGUOI_DAI_DIEN%}", ContactName);

                            //Bill No
                            xlsSheetEn[rBillNo, cBillNo].Value = xlsSheetEn[rBillNo, cBillNo].Value.ToString().Replace("{%BILL_NO%}", BillNo);
                            ///////////////////////////////////////////
                            //Ngay Thang Nam
                            DateTime dtime = DateTime.Today;

                            string strTmp = xlsSheet[rBillDate, cBillDate].Value.ToString().Replace("{%NGAY%}", dtime.ToString("dd"));
                            strTmp = strTmp.Replace("{%THANG%}", dtime.ToString("MM"));
                            xlsSheet[rBillDate, cBillDate].Value = strTmp.Replace("{%NAM%}", dtime.ToString("yyyy"));

                            strTmp = xlsSheetEn[rBillDate, cBillDate].Value.ToString().Replace("{%NGAY%}", dtime.ToString("dd"));
                            strTmp = strTmp.Replace("{%THANG%}", dtime.ToString("MM"));
                            xlsSheetEn[rBillDate, cBillDate].Value = strTmp.Replace("{%NAM%}", dtime.ToString("yyyy"));

                            //Nam
                            xlsSheet[rBillMonth, cBillMonth].Value = xlsSheet[rBillMonth, cBillMonth].Value.ToString().Replace("{%NAM_THANG%}", sMonth + "/" + sYear);
                            xlsSheetEn[rBillMonth, cBillMonth].Value = xlsSheetEn[rBillMonth, cBillMonth].Value.ToString().Replace("{%NAM_THANG%}", sMonth + "/" + sYear);

                            //Thông tin Tỉ giá
                            xlsSheet[rRate, cRate].Value = xlsSheet[rRate, cRate].Value.ToString().Replace("{%TI_GIA%}", UsdExchange);
                            xlsSheet[rRateDate, cRateDate].Value = xlsSheet[rRateDate, cRateDate].Value.ToString().Replace("{%NGAY_AP_DUNG%}", UsdExchangeDate);
                            //Thông tin Tỉ giá
                            xlsSheetEn[rRate, cRate].Value = xlsSheetEn[rRate, cRate].Value.ToString().Replace("{%TI_GIA%}", UsdExchange);
                            xlsSheetEn[rRateDate, cRateDate].Value = xlsSheetEn[rRateDate, cRateDate].Value.ToString().Replace("{%NGAY_AP_DUNG%}", UsdExchangeDate);

                            Hashtable contractIdLst = new Hashtable();
                            string contract = "";
                            ////

                            //Thue phong
                            ds = new DataSet();
                            sql = " Select A.*, B.ContractDate";
                            sql += " FROM PaymentRoom A, RentContract B";
                            sql += " WHERE A.ContractId = B.ContractId and A.BuildingId = B.BuildingId and A.BuildingId = '" + sBuildingId + "' and A.CustomerId = '" + CustomerId + "' and A.YearMonth in (" + lsYearmonth + ")";

                            int sumRow = 0;
                            int j = 0;
                            decimal[] LastSumPriceVND = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 };
                            decimal[] LastSumPriceUSD = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 };

                            decimal PaidPriceVND = 0;
                            decimal PaidPriceUSD = 0;

                            int line = 0;
                            using (SqlCommand cm = db.CreateCommand(sql))
                            {
                                SqlDataAdapter da = new SqlDataAdapter(cm);
                                da.Fill(ds);

                                line = rRent - 3 + j;

                                XLCellRange mCell = new XLCellRange(line, line + 2, 1, 3);
                                xlsSheet.MergedCells.Add(mCell);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 4, 5);
                                xlsSheet.MergedCells.Add(mCell);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 4, 5);
                                xlsSheet.MergedCells.Add(mCell);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 2, line + 2, 4, 5);
                                xlsSheet.MergedCells.Add(mCell);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 6, 7);
                                xlsSheet.MergedCells.Add(mCell);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 6, 7);
                                xlsSheet.MergedCells.Add(mCell);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 8, 9);
                                xlsSheet.MergedCells.Add(mCell);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 8, 9);
                                xlsSheet.MergedCells.Add(mCell);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 10, 11);
                                xlsSheet.MergedCells.Add(mCell);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 10, 11);
                                xlsSheet.MergedCells.Add(mCell);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 12, 13);
                                xlsSheet.MergedCells.Add(mCell);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 12, 13);
                                xlsSheet.MergedCells.Add(mCell);
                                xlsSheetEn.MergedCells.Add(mCell);

                                if (ds != null)
                                {
                                    int count = 0;
                                    DataTable dt = ds.Tables[0];
                                    int k = 0;
                                    foreach (DataRow rowType in dt.Rows)
                                    {
                                        decimal tmp01 = Convert.ToDecimal(rowType["LastRentSumUSD"]);
                                        decimal tmp02 = Convert.ToDecimal(rowType["LastRentSumVND"]);

                                        string ContractId = Func.ParseString(rowType["ContractId"]);
                                        string ContractNo = Func.ParseString(rowType["ContractNo"]);
                                        string YearMonth = Func.ParseString(rowType["YearMonth"]);
                                        string Area = Func.ParseString(rowType["Area"]);
                                        string Regional = Func.ParseString(rowType["Regional"]);
                                        string Floor = Func.ParseString(rowType["Floor"]);
                                        string BeginContract = Func.ParseString(rowType["ContractDate"]);

                                        if (!contractIdLst.ContainsKey(ContractId + "(" + Func.FormatDMY(BeginContract) + ")"))
                                        {
                                            contractIdLst.Add(ContractId + "(" + Func.FormatDMY(BeginContract) + ")", ContractNo + "(" + Func.FormatDMY(BeginContract) + ")");
                                            contract += ";" + ContractNo + "(" + Func.FormatDMY(BeginContract) + ")";
                                        }
                                        if (tmp01 > 0 || tmp02 > 0)
                                        {

                                            if (count >= 1)
                                            {
                                                xlsSheet.Rows.Insert(rRent + 1 + j);
                                                xlsSheetEn.Rows.Insert(rRent + 1 + j);
                                                j++;
                                            }
                                            count++;
                                            int tmp = rRent + j;
                                            xlsSheet[tmp, 1].Value = Name;
                                            xlsSheet[tmp, 4].Value = rowType["Area"];
                                            xlsSheet[tmp, 6].Value = rowType["MonthRentPriceUSD"];
                                            xlsSheet[tmp, 7].Value = rowType["MonthRentPriceVND"];

                                            xlsSheet[tmp, 8].Value = rowType["MonthRentSumUSD"];
                                            xlsSheet[tmp, 9].Value = rowType["MonthRentSumVND"];

                                            xlsSheet[tmp, 10].Value = rowType["VatRentPriceUSD"];
                                            xlsSheet[tmp, 11].Value = rowType["VatRentPriceVND"];

                                            xlsSheet[tmp, 12].Value = rowType["LastRentSumUSD"];
                                            xlsSheet[tmp, 13].Value = rowType["LastRentSumVND"];

                                            XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3);
                                            xlsSheet.MergedCells.Add(mrCell);

                                            mrCell = new XLCellRange(tmp, tmp, 4, 5);
                                            xlsSheet.MergedCells.Add(mrCell);

                                            ////EN
                                            xlsSheetEn[tmp, 1].Value = Name;
                                            xlsSheetEn[tmp, 4].Value = rowType["Area"];
                                            xlsSheetEn[tmp, 6].Value = rowType["MonthRentPriceUSD"];
                                            xlsSheetEn[tmp, 7].Value = rowType["MonthRentPriceVND"];

                                            xlsSheetEn[tmp, 8].Value = rowType["MonthRentSumUSD"];
                                            xlsSheetEn[tmp, 9].Value = rowType["MonthRentSumVND"];

                                            xlsSheetEn[tmp, 10].Value = rowType["VatRentPriceUSD"];
                                            xlsSheetEn[tmp, 11].Value = rowType["VatRentPriceVND"];

                                            xlsSheetEn[tmp, 12].Value = rowType["LastRentSumUSD"];
                                            xlsSheetEn[tmp, 13].Value = rowType["LastRentSumVND"];

                                            mrCell = new XLCellRange(tmp, tmp, 1, 3);
                                            xlsSheetEn.MergedCells.Add(mrCell);

                                            mrCell = new XLCellRange(tmp, tmp, 4, 5);
                                            xlsSheetEn.MergedCells.Add(mrCell);
                                            ////EN

                                            LastSumPriceVND[0] += Convert.ToDecimal(rowType["LastRentSumVND"]);
                                            LastSumPriceUSD[0] += Convert.ToDecimal(rowType["LastRentSumUSD"]);
                                        }
                                        else
                                        {
                                            k++;
                                        }
                                    }
                                    mCell = new XLCellRange(rRent + 1 + j, rRent + 1 + j, 1, 11);
                                    xlsSheet.MergedCells.Add(mCell);
                                    xlsSheetEn.MergedCells.Add(mCell);

                                    xlsSheet[rRent + 1 + j, 12].Value = LastSumPriceUSD[0];
                                    xlsSheet[rRent + 1 + j, 13].Value = LastSumPriceVND[0];

                                    xlsSheetEn[rRent + 1 + j, 12].Value = LastSumPriceUSD[0];
                                    xlsSheetEn[rRent + 1 + j, 13].Value = LastSumPriceVND[0];

                                    for (int row = rRent + sumRow; row <= rRent + dt.Rows.Count - k; row++)
                                    {
                                        for (int col = 1; col <= 13; col++)
                                        {
                                            xlsSheet[row, col].Style = xlstStyle;
                                            xlsSheetEn[row, col].Style = xlstStyle;
                                        }
                                    }
                                    sumRow += dt.Rows.Count - 1 - k;

                                    ////////////////////////
                                    for (int col = 1; col <= 13; col++)
                                    {
                                        xlsSheet[rRent + 1 + j, col].Style = xlstStyleSum;
                                        xlsSheetEn[rRent + 1 + j, col].Style = xlstStyleSum;
                                    }
                                    line = rManager - 3 + j;
                                    mCell = new XLCellRange(line, line + 2, 1, 3);
                                    xlsSheet.MergedCells.Add(mCell);

                                    mCell = new XLCellRange(line, line, 4, 5);
                                    xlsSheet.MergedCells.Add(mCell);

                                    mCell = new XLCellRange(line + 1, line + 1, 4, 5);
                                    xlsSheet.MergedCells.Add(mCell);

                                    mCell = new XLCellRange(line + 2, line + 2, 4, 5);
                                    xlsSheet.MergedCells.Add(mCell);

                                    mCell = new XLCellRange(line, line, 6, 7);
                                    xlsSheet.MergedCells.Add(mCell);

                                    mCell = new XLCellRange(line + 1, line + 1, 6, 7);
                                    xlsSheet.MergedCells.Add(mCell);

                                    mCell = new XLCellRange(line, line, 8, 9);
                                    xlsSheet.MergedCells.Add(mCell);

                                    mCell = new XLCellRange(line + 1, line + 1, 8, 9);
                                    xlsSheet.MergedCells.Add(mCell);

                                    mCell = new XLCellRange(line, line, 10, 11);
                                    xlsSheet.MergedCells.Add(mCell);

                                    mCell = new XLCellRange(line + 1, line + 1, 10, 11);
                                    xlsSheet.MergedCells.Add(mCell);

                                    mCell = new XLCellRange(line, line, 12, 13);
                                    xlsSheet.MergedCells.Add(mCell);

                                    mCell = new XLCellRange(line + 1, line + 1, 12, 13);
                                    xlsSheet.MergedCells.Add(mCell);

                                    ////En
                                    mCell = new XLCellRange(line, line + 2, 1, 3);
                                    xlsSheetEn.MergedCells.Add(mCell);

                                    mCell = new XLCellRange(line, line, 4, 5);
                                    xlsSheetEn.MergedCells.Add(mCell);

                                    mCell = new XLCellRange(line + 1, line + 1, 4, 5);
                                    xlsSheetEn.MergedCells.Add(mCell);

                                    mCell = new XLCellRange(line + 2, line + 2, 4, 5);
                                    xlsSheetEn.MergedCells.Add(mCell);

                                    mCell = new XLCellRange(line, line, 6, 7);
                                    xlsSheetEn.MergedCells.Add(mCell);

                                    mCell = new XLCellRange(line + 1, line + 1, 6, 7);
                                    xlsSheetEn.MergedCells.Add(mCell);

                                    mCell = new XLCellRange(line, line, 8, 9);
                                    xlsSheetEn.MergedCells.Add(mCell);

                                    mCell = new XLCellRange(line + 1, line + 1, 8, 9);
                                    xlsSheetEn.MergedCells.Add(mCell);

                                    mCell = new XLCellRange(line, line, 10, 11);
                                    xlsSheetEn.MergedCells.Add(mCell);

                                    mCell = new XLCellRange(line + 1, line + 1, 10, 11);
                                    xlsSheetEn.MergedCells.Add(mCell);

                                    mCell = new XLCellRange(line, line, 12, 13);
                                    xlsSheetEn.MergedCells.Add(mCell);

                                    mCell = new XLCellRange(line + 1, line + 1, 12, 13);
                                    xlsSheetEn.MergedCells.Add(mCell);
                                    ////En
                                    k = 0;
                                    count = 0;
                                    foreach (DataRow row in dt.Rows)
                                    {
                                        decimal tmp01 = Convert.ToDecimal(row["LastManagerSumUSD"]);
                                        decimal tmp02 = Convert.ToDecimal(row["LastManagerSumVND"]);

                                        if (tmp01 > 0 || tmp02 > 0)
                                        {

                                            if (count >= 1)
                                            {
                                                xlsSheet.Rows.Insert(rManager + 1 + j);
                                                xlsSheetEn.Rows.Insert(rManager + 1 + j);
                                                j++;
                                            }
                                            count++;
                                            int tmp = rManager + j;

                                            string YearMonth = Func.ParseString(row["YearMonth"]);
                                            string Area = Func.ParseString(row["Area"]);

                                            xlsSheet[tmp, 1].Value = Name;
                                            xlsSheet[tmp, 4].Value = row["Area"];
                                            xlsSheet[tmp, 6].Value = row["MonthManagerPriceUSD"];
                                            xlsSheet[tmp, 7].Value = row["MonthManagerPriceVND"];

                                            xlsSheet[tmp, 8].Value = row["MonthManagerSumUSD"];
                                            xlsSheet[tmp, 9].Value = row["MonthManagerSumVND"];

                                            xlsSheet[tmp, 10].Value = row["VatManagerPriceUSD"];
                                            xlsSheet[tmp, 11].Value = row["VatManagerPriceVND"];

                                            xlsSheet[tmp, 12].Value = row["LastManagerSumUSD"];
                                            xlsSheet[tmp, 13].Value = row["LastManagerSumVND"];

                                            XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3);
                                            xlsSheet.MergedCells.Add(mrCell);

                                            mrCell = new XLCellRange(tmp, tmp, 4, 5);
                                            xlsSheet.MergedCells.Add(mrCell);

                                            ////En
                                            xlsSheetEn[tmp, 1].Value = Name;
                                            xlsSheetEn[tmp, 4].Value = row["Area"];
                                            xlsSheetEn[tmp, 6].Value = row["MonthManagerPriceUSD"];
                                            xlsSheetEn[tmp, 7].Value = row["MonthManagerPriceVND"];

                                            xlsSheetEn[tmp, 8].Value = row["MonthManagerSumUSD"];
                                            xlsSheetEn[tmp, 9].Value = row["MonthManagerSumVND"];

                                            xlsSheetEn[tmp, 10].Value = row["VatManagerPriceUSD"];
                                            xlsSheetEn[tmp, 11].Value = row["VatManagerPriceVND"];

                                            xlsSheetEn[tmp, 12].Value = row["LastManagerSumUSD"];
                                            xlsSheetEn[tmp, 13].Value = row["LastManagerSumVND"];

                                            mrCell = new XLCellRange(tmp, tmp, 1, 3);
                                            xlsSheetEn.MergedCells.Add(mrCell);

                                            mrCell = new XLCellRange(tmp, tmp, 4, 5);
                                            xlsSheetEn.MergedCells.Add(mrCell);
                                            ////En
                                            LastSumPriceVND[1] += Convert.ToDecimal(row["LastManagerSumVND"]);
                                            LastSumPriceUSD[1] += Convert.ToDecimal(row["LastManagerSumUSD"]);
                                        }
                                        else { k++; }
                                    }
                                    mCell = new XLCellRange(rManager + 1 + j, rManager + 1 + j, 1, 11);
                                    xlsSheet.MergedCells.Add(mCell);
                                    xlsSheetEn.MergedCells.Add(mCell);

                                    xlsSheet[rManager + 1 + j, 12].Value = LastSumPriceUSD[1];
                                    xlsSheet[rManager + 1 + j, 13].Value = LastSumPriceVND[1];

                                    xlsSheetEn[rManager + 1 + j, 12].Value = LastSumPriceUSD[1];
                                    xlsSheetEn[rManager + 1 + j, 13].Value = LastSumPriceVND[1];

                                    for (int row = rManager + sumRow; row <= rManager + sumRow + dt.Rows.Count - k; row++)
                                    {
                                        for (int col = 1; col <= 13; col++)
                                        {
                                            xlsSheet[row, col].Style = xlstStyle;
                                            xlsSheetEn[row, col].Style = xlstStyle;
                                        }
                                    }

                                    for (int col = 1; col <= 13; col++)
                                    {
                                        xlsSheet[rManager + 1 + j, col].Style = xlstStyleSum;
                                        xlsSheetEn[rManager + 1 + j, col].Style = xlstStyleSum;
                                    }
                                    sumRow += dt.Rows.Count - 1 - k;
                                }
                            }

                            ds = new DataSet();
                            //Xuất ra toàn bộ nội dung theo Trang
                            sql = " SELECT COUNT(*) AS Num, YearMonth, TariffsParkingName, PriceVND, PriceUSD, SUM(VatVND) AS VatVND,SUM(VatUSD) AS VatUSD, SUM(SumVND) AS SumVND, SUM(SumUSD) AS SumUSD, SUM(LastPriceVND) AS LastPriceVND";
                            sql += "        , SUM(LastPriceUSD) AS LastPriceUSD";
                            sql += " FROM         dbo.PaymentParking";
                            sql += " WHERE BuildingId = '" + sBuildingId + "' and CustomerId = '" + CustomerId + "' and YearMonth in (" + lsYearmonth + ")";

                            sql += " GROUP BY YearMonth, TariffsParkingName, PriceVND, PriceUSD, Vat, daysParking";
                            sql += " HAVING (SUM(LastPriceVND) >0 or SUM(LastPriceUSD) >0)";
                            using (SqlCommand cm = db.CreateCommand(sql))
                            {
                                SqlDataAdapter da = new SqlDataAdapter(cm);
                                da.Fill(ds);

                                line = rParking - 3 + j;
                                XLCellRange mCell = new XLCellRange(line, line + 2, 1, 3);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 4, 5);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 4, 5);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 2, line + 2, 4, 5);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 6, 7);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 6, 7);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 8, 9);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 8, 9);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 10, 11);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 10, 11);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 12, 13);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 12, 13);
                                xlsSheet.MergedCells.Add(mCell);

                                ////En
                                mCell = new XLCellRange(line, line + 2, 1, 3);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 4, 5);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 4, 5);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 2, line + 2, 4, 5);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 6, 7);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 6, 7);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 8, 9);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 8, 9);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 10, 11);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 10, 11);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 12, 13);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 12, 13);
                                xlsSheetEn.MergedCells.Add(mCell);
                                ////En
                                if (ds != null)
                                {
                                    int count = 0;
                                    DataTable dt = ds.Tables[0];

                                    foreach (DataRow row in dt.Rows)
                                    {
                                        if (count >= 1)
                                        {
                                            xlsSheet.Rows.Insert(rParking + 1 + j);
                                            xlsSheetEn.Rows.Insert(rParking + 1 + j);
                                            j++;
                                        }
                                        count++;
                                        int tmp = rParking + j;

                                        string Num = Func.ParseString(row["Num"]);
                                        string TariffsParkingName = Func.ParseString(row["TariffsParkingName"]);

                                        xlsSheet[tmp, 1].Value = TariffsParkingName;
                                        xlsSheet[tmp, 4].Value = Num;
                                        xlsSheet[tmp, 6].Value = row["PriceUSD"];
                                        xlsSheet[tmp, 7].Value = row["PriceVND"];

                                        xlsSheet[tmp, 8].Value = row["SumUSD"];
                                        xlsSheet[tmp, 9].Value = row["SumVND"];

                                        xlsSheet[tmp, 10].Value = row["VatUSD"];
                                        xlsSheet[tmp, 11].Value = row["VatVND"];

                                        xlsSheet[tmp, 12].Value = row["LastPriceUSD"];
                                        xlsSheet[tmp, 13].Value = row["LastPriceVND"];

                                        XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3);
                                        xlsSheet.MergedCells.Add(mrCell);

                                        mrCell = new XLCellRange(tmp, tmp, 4, 5);
                                        xlsSheet.MergedCells.Add(mrCell);

                                        /////En
                                        xlsSheetEn[tmp, 1].Value = TariffsParkingName;
                                        xlsSheetEn[tmp, 4].Value = Num;
                                        xlsSheetEn[tmp, 6].Value = row["PriceUSD"];
                                        xlsSheetEn[tmp, 7].Value = row["PriceVND"];

                                        xlsSheetEn[tmp, 8].Value = row["SumUSD"];
                                        xlsSheetEn[tmp, 9].Value = row["SumVND"];

                                        xlsSheetEn[tmp, 10].Value = row["VatUSD"];
                                        xlsSheetEn[tmp, 11].Value = row["VatVND"];

                                        xlsSheetEn[tmp, 12].Value = row["LastPriceUSD"];
                                        xlsSheetEn[tmp, 13].Value = row["LastPriceVND"];

                                        mrCell = new XLCellRange(tmp, tmp, 1, 3);
                                        xlsSheetEn.MergedCells.Add(mrCell);

                                        mrCell = new XLCellRange(tmp, tmp, 4, 5);
                                        xlsSheetEn.MergedCells.Add(mrCell);
                                        /////En
                                        LastSumPriceVND[2] += Convert.ToDecimal(row["LastPriceVND"]);
                                        LastSumPriceUSD[2] += Convert.ToDecimal(row["LastPriceUSD"]);
                                    }
                                    xlsSheet[rParking + 1 + j, 12].Value = LastSumPriceUSD[2];
                                    xlsSheet[rParking + 1 + j, 13].Value = LastSumPriceVND[2];

                                    mCell = new XLCellRange(rParking + 1 + j, rParking + 1 + j, 1, 11);
                                    xlsSheet.MergedCells.Add(mCell);

                                    /////En
                                    xlsSheetEn[rParking + 1 + j, 12].Value = LastSumPriceUSD[2];
                                    xlsSheetEn[rParking + 1 + j, 13].Value = LastSumPriceVND[2];

                                    mCell = new XLCellRange(rParking + 1 + j, rParking + 1 + j, 1, 11);
                                    xlsSheetEn.MergedCells.Add(mCell);
                                    /////En

                                    for (int row = rParking + sumRow; row <= rParking + sumRow + dt.Rows.Count; row++)
                                    {
                                        for (int col = 1; col <= 13; col++)
                                        {
                                            xlsSheet[row, col].Style = xlstStyle;
                                            xlsSheetEn[row, col].Style = xlstStyle;
                                        }
                                    }

                                    for (int col = 1; col <= 13; col++)
                                    {
                                        xlsSheet[rParking + 1 + j, col].Style = xlstStyleSum;
                                        xlsSheetEn[rParking + 1 + j, col].Style = xlstStyleSum;
                                    }
                                    sumRow += dt.Rows.Count - 1;
                                }
                            }

                            ds = new DataSet();
                            sql = "SELECT id";
                            sql += " ,YearMonth,BuildingId,CustomerId,RoomId,ExtraHour,VAT,OtherFee01,OtherFee02";
                            sql += " ,PriceUSD,PriceVND,VatUSD,VatVND,SumUSD,SumVND,IsNull(LastPriceUSD,0) LastPriceUSD      ,IsNull(LastPriceVND,0) LastPriceVND ";
                            sql += " ,RentArea,dbo.fnDateTime(FromWD) BeginDate,dbo.fnDateTime(EndWD) EndDate,ExtratimeType";
                            sql += " FROM PaymentExtraTimeMonth";
                            sql += " WHERE BuildingId = '" + sBuildingId + "' and CustomerId = '" + CustomerId + "' and YearMonth in (" + lsYearmonth + ")";

                            using (SqlCommand cm = db.CreateCommand(sql))
                            {
                                SqlDataAdapter da = new SqlDataAdapter(cm);
                                da.Fill(ds);
                                line = rExtra - 3 + j;
                                //Phi dien
                                XLCellRange mCell = new XLCellRange(line, line + 2, 1, 3);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line + 2, 4, 4);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 6, 7);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 6, 7);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 8, 9);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 8, 9);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 10, 11);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 10, 11);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 12, 13);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 12, 13);
                                xlsSheet.MergedCells.Add(mCell);

                                /////En
                                mCell = new XLCellRange(line, line + 2, 1, 3);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line + 2, 4, 4);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 6, 7);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 6, 7);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 8, 9);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 8, 9);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 10, 11);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 10, 11);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 12, 13);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 12, 13);
                                xlsSheetEn.MergedCells.Add(mCell);
                                /////En
                                if (ds != null)
                                {
                                    int count = 0;
                                    DataTable dt = ds.Tables[0];

                                    foreach (DataRow row in dt.Rows)
                                    {
                                        if (count >= 1)
                                        {
                                            xlsSheet.Rows.Insert(rExtra + 1 + j);
                                            xlsSheetEn.Rows.Insert(rExtra + 1 + j);
                                            j++;
                                        }
                                        count++;
                                        int tmp = rExtra + j;

                                        string ExtraHour = Func.ParseString(row["ExtraHour"]);
                                        string BeginDate = Func.ParseString(row["BeginDate"]);
                                        string EndDate = Func.ParseString(row["EndDate"]);

                                        string ExtratimeType = Func.ParseString(row["ExtratimeType"]);

                                        xlsSheet[tmp, 1].Value = BeginDate + "~" + EndDate;
                                        xlsSheet[tmp, 5].Value = ExtraHour;

                                        xlsSheet[tmp, 4].Value = "Diện tích";
                                        if ("0".Equals(ExtratimeType))
                                        {
                                            xlsSheet[tmp, 4].Value = "m2*h";
                                        }
                                        xlsSheet[tmp, 6].Value = row["PriceUSD"];
                                        xlsSheet[tmp, 7].Value = row["PriceVND"];

                                        xlsSheet[tmp, 8].Value = row["SumUSD"];
                                        xlsSheet[tmp, 9].Value = row["SumVND"];

                                        xlsSheet[tmp, 10].Value = row["VatUSD"];
                                        xlsSheet[tmp, 11].Value = row["VatVND"];

                                        xlsSheet[tmp, 12].Value = row["LastPriceUSD"];
                                        xlsSheet[tmp, 13].Value = row["LastPriceVND"];

                                        LastSumPriceVND[3] += Convert.ToDecimal(row["LastPriceVND"]);
                                        LastSumPriceUSD[3] += Convert.ToDecimal(row["LastPriceUSD"]);

                                        XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3);
                                        xlsSheet.MergedCells.Add(mrCell);
                                        //////En
                                        xlsSheetEn[tmp, 1].Value = BeginDate + "~" + EndDate;
                                        xlsSheetEn[tmp, 5].Value = ExtraHour;

                                        xlsSheetEn[tmp, 4].Value = "Di?n tích";
                                        if ("0".Equals(ExtratimeType))
                                        {
                                            xlsSheetEn[tmp, 4].Value = "m2*h";
                                        }
                                        xlsSheetEn[tmp, 6].Value = row["PriceUSD"];
                                        xlsSheetEn[tmp, 7].Value = row["PriceVND"];

                                        xlsSheetEn[tmp, 8].Value = row["SumUSD"];
                                        xlsSheetEn[tmp, 9].Value = row["SumVND"];

                                        xlsSheetEn[tmp, 10].Value = row["VatUSD"];
                                        xlsSheetEn[tmp, 11].Value = row["VatVND"];

                                        xlsSheetEn[tmp, 12].Value = row["LastPriceUSD"];
                                        xlsSheetEn[tmp, 13].Value = row["LastPriceVND"];

                                        //LastSumPriceVND[3] += Convert.ToDecimal(row["LastPriceVND"]);
                                        //LastSumPriceUSD[3] += Convert.ToDecimal(row["LastPriceUSD"]);

                                        mrCell = new XLCellRange(tmp, tmp, 1, 3);
                                        xlsSheetEn.MergedCells.Add(mrCell);
                                        //////En

                                        for (int col = 1; col <= 13; col++)
                                        {
                                            xlsSheet[tmp, col].Style = xlstStyle;
                                            xlsSheetEn[tmp, col].Style = xlstStyle;
                                        }

                                    }
                                    mCell = new XLCellRange(rExtra + 1 + j, rExtra + 1 + j, 1, 11);
                                    xlsSheet.MergedCells.Add(mCell);
                                    xlsSheetEn.MergedCells.Add(mCell);

                                    xlsSheet[rExtra + 1 + j, 12].Value = LastSumPriceUSD[3];
                                    xlsSheet[rExtra + 1 + j, 13].Value = LastSumPriceVND[3];

                                    xlsSheetEn[rExtra + 1 + j, 12].Value = LastSumPriceUSD[3];
                                    xlsSheetEn[rExtra + 1 + j, 13].Value = LastSumPriceVND[3];

                                    for (int row = rExtra + sumRow; row <= rExtra + sumRow + dt.Rows.Count; row++)
                                    {
                                        for (int col = 1; col <= 13; col++)
                                        {
                                            xlsSheet[row, col].Style = xlstStyle;
                                            xlsSheetEn[row, col].Style = xlstStyle;
                                        }
                                    }

                                    for (int col = 1; col <= 13; col++)
                                    {
                                        xlsSheet[rExtra + 1 + j, col].Style = xlstStyleSum;
                                        xlsSheetEn[rExtra + 1 + j, col].Style = xlstStyleSum;
                                    }
                                    sumRow += dt.Rows.Count - 1;
                                }
                            }

                            ds = new DataSet();
                            //Dien
                            //Xuất ra toàn bộ nội dung theo Trang
                            sql = " SELECT dbo.fnDateTime(A.DateFrom) DateFrom, dbo.fnDateTime(A.DateTo) DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.OtherFee02, B.Mount, B.PriceVND, B.PriceUSD, B.SumVND, B.SumUSD, ";
                            sql += "        B.VatVND, B.VatUSD ,IsNull(B.LastPriceUSD,0) LastPriceUSD      ,IsNull(B.LastPriceVND,0) LastPriceVND , B.Name, B.WaterPricePercent,B.ElecPricePercent ";
                            sql += " FROM   PaymentElecWater AS A INNER JOIN ";
                            sql += "        PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId";
                            sql += " WHERE A.BuildingId = '" + sBuildingId + "' and A.CustomerId = '" + CustomerId + "' and TarrifsOfWaterId = 0  and A.YearMonth in (" + lsYearmonth + ")";
                            sql += " Order by A.DateFrom, B.FromIndex";

                            using (SqlCommand cm = db.CreateCommand(sql))
                            {
                                SqlDataAdapter da = new SqlDataAdapter(cm);
                                da.Fill(ds);

                                line = rElec - 3 + j;
                                //Phi dien
                                XLCellRange mCell = new XLCellRange(line, line + 2, 1, 1);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line + 2, 2, 2);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 3, 3);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 4, 4);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 5, 5);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 7, 7);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 8, 8);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 9, 9);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 10, 10);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 11, 11);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 12, 13);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 12, 13);
                                xlsSheet.MergedCells.Add(mCell);
                                /////En
                                mCell = new XLCellRange(line, line + 2, 1, 1);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line + 2, 2, 2);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 3, 3);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 4, 4);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 5, 5);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 7, 7);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 8, 8);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 9, 9);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 10, 10);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 11, 11);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 12, 13);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 12, 13);
                                xlsSheetEn.MergedCells.Add(mCell);
                                /////En

                                for (int col = 1; col < 13; col++)
                                {
                                    xlsSheet[line, col].Style = xlstStyleH;
                                    xlsSheet[line + 1, col].Style = xlstStyleH;
                                    xlsSheet[line + 2, col].Style = xlstStyleH;

                                    xlsSheetEn[line, col].Style = xlstStyleH;
                                    xlsSheetEn[line + 1, col].Style = xlstStyleH;
                                    xlsSheetEn[line + 2, col].Style = xlstStyleH;
                                }

                                if (ds != null)
                                {
                                    int count = 0;
                                    DataTable dt = ds.Tables[0];
                                    if (dt.Rows.Count > 0)
                                    {
                                        foreach (DataRow row in dt.Rows)
                                        {
                                            if (count >= 1)
                                            {
                                                xlsSheet.Rows.Insert(rElec + 1 + j);
                                                xlsSheetEn.Rows.Insert(rElec + 1 + j);
                                                j++;

                                            }
                                            count++;
                                            int tmp = rElec + j;

                                            string DateFrom = Func.ParseString(row["DateFrom"]);
                                            string DateTo = Func.ParseString(row["DateTo"]);

                                            string FromIndex = Func.ParseString(row["FromIndex"]);
                                            string ToIndex = Func.ParseString(row["ToIndex"]);
                                            string OtherFee01 = Func.ParseString(row["OtherFee01"]);
                                            string OtherFee02 = Func.ParseString(row["OtherFee02"]);
                                            string Mount = Func.ParseString(row["Mount"]);
                                            string ElecPricePercent = Func.ParseString(row["ElecPricePercent"]);

                                            xlsSheet[tmp, 1].Value = DateFrom;
                                            xlsSheet[tmp, 2].Value = DateTo;
                                            xlsSheet[tmp, 3].Value = FromIndex;
                                            xlsSheet[tmp, 4].Value = ToIndex;
                                            xlsSheet[tmp, 5].Value = OtherFee01;
                                            xlsSheet[tmp, 6].Value = Mount;
                                            xlsSheet[tmp, 7].Value = row["PriceVND"];
                                            xlsSheet[tmp, 8].Value = row["VatVND"];

                                            xlsSheet[tmp, 9].Value = row["SumVND"];
                                            xlsSheet[tmp, 10].Value = row["OtherFee02"];
                                            xlsSheet[tmp, 11].Value = row["ElecPricePercent"];
                                            xlsSheet[tmp, 12].Value = row["LastPriceVND"];

                                            mCell = new XLCellRange(tmp, tmp, 12, 13);
                                            xlsSheet.MergedCells.Add(mCell);

                                            /////En
                                            xlsSheetEn[tmp, 1].Value = DateFrom;
                                            xlsSheetEn[tmp, 2].Value = DateTo;
                                            xlsSheetEn[tmp, 3].Value = FromIndex;
                                            xlsSheetEn[tmp, 4].Value = ToIndex;
                                            xlsSheetEn[tmp, 5].Value = OtherFee01;
                                            xlsSheetEn[tmp, 6].Value = Mount;
                                            xlsSheetEn[tmp, 7].Value = row["PriceVND"];
                                            xlsSheetEn[tmp, 8].Value = row["VatVND"];

                                            xlsSheetEn[tmp, 9].Value = row["SumVND"];
                                            xlsSheetEn[tmp, 10].Value = row["OtherFee02"];
                                            xlsSheetEn[tmp, 11].Value = row["ElecPricePercent"];
                                            xlsSheetEn[tmp, 12].Value = row["LastPriceVND"];

                                            mCell = new XLCellRange(tmp, tmp, 12, 13);
                                            xlsSheetEn.MergedCells.Add(mCell);
                                            /////En
                                            for (int col = 1; col <= 12; col++)
                                            {
                                                xlsSheet[tmp, col].Style = xlstStyle;
                                                xlsSheetEn[tmp, col].Style = xlstStyle;
                                            }
                                            LastSumPriceVND[4] += Convert.ToDecimal(row["LastPriceVND"]);
                                            LastSumPriceUSD[4] += Convert.ToDecimal(row["LastPriceUSD"]);
                                        }
                                        xlsSheet[rElec + 1 + j, 12].Value = LastSumPriceVND[4];
                                        mCell = new XLCellRange(rElec + 1 + j, rElec + 1 + j, 1, 11);
                                        xlsSheet.MergedCells.Add(mCell);

                                        mCell = new XLCellRange(rElec + 1 + j, rElec + 1 + j, 12, 13);
                                        xlsSheet.MergedCells.Add(mCell);

                                        xlsSheetEn[rElec + 1 + j, 12].Value = LastSumPriceVND[4];
                                        mCell = new XLCellRange(rElec + 1 + j, rElec + 1 + j, 1, 11);
                                        xlsSheetEn.MergedCells.Add(mCell);

                                        mCell = new XLCellRange(rElec + 1 + j, rElec + 1 + j, 12, 13);
                                        xlsSheetEn.MergedCells.Add(mCell);

                                        for (int col = 1; col <= 13; col++)
                                        {
                                            xlsSheet[rElec + 1 + j, col].Style = xlstStyleSum;
                                            xlsSheetEn[rElec + 1 + j, col].Style = xlstStyleSum;
                                        }
                                        sumRow += dt.Rows.Count - 1;
                                    }
                                }
                            }

                            ds = new DataSet();
                            //Nuoc
                            //Xuất ra toàn bộ nội dung theo Trang
                            sql = " SELECT dbo.fnDateTime(A.DateFrom) DateFrom, dbo.fnDateTime(A.DateTo) DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.OtherFee02, B.Mount, B.PriceVND, B.PriceUSD, B.SumVND, B.SumUSD, ";
                            sql += "        B.VatVND, B.VatUSD,IsNull(B.LastPriceUSD,0) LastPriceUSD,IsNull(B.LastPriceVND,0) LastPriceVND, B.Name, B.WaterPricePercent,B.ElecPricePercent  ";
                            sql += " FROM   PaymentElecWater AS A INNER JOIN ";
                            sql += "        PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId";
                            sql += " WHERE A.BuildingId = '" + sBuildingId + "' and A.CustomerId = '" + CustomerId + "' and TarrifsOfElecId = 0 and A.YearMonth in (" + lsYearmonth + ")";
                            sql += " Order by A.DateFrom, B.FromIndex";

                            using (SqlCommand cm = db.CreateCommand(sql))
                            {
                                SqlDataAdapter da = new SqlDataAdapter(cm);
                                da.Fill(ds);
                                line = rWater - 3 + j;
                                //Phi dien
                                XLCellRange mCell = new XLCellRange(line, line + 2, 1, 1);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line + 2, 2, 2);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 3, 3);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 4, 4);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 6, 6);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 7, 7);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 8, 8);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 9, 9);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 10, 10);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 11, 11);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 12, 13);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 12, 13);
                                xlsSheet.MergedCells.Add(mCell);

                                /////En
                                mCell = new XLCellRange(line, line + 2, 1, 1);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line + 2, 2, 2);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 3, 3);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 4, 4);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 6, 6);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 7, 7);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 8, 8);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 9, 9);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 10, 10);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 11, 11);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 12, 13);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 12, 13);
                                xlsSheetEn.MergedCells.Add(mCell);
                                /////En

                                for (int col = 1; col < 13; col++)
                                {
                                    xlsSheet[line, col].Style = xlstStyleH;
                                    xlsSheet[line + 1, col].Style = xlstStyleH;
                                    xlsSheet[line + 2, col].Style = xlstStyleH;

                                    xlsSheetEn[line, col].Style = xlstStyleH;
                                    xlsSheetEn[line + 1, col].Style = xlstStyleH;
                                    xlsSheetEn[line + 2, col].Style = xlstStyleH;
                                }

                                if (ds != null)
                                {
                                    int count = 0;
                                    DataTable dt = ds.Tables[0];
                                    if (dt.Rows.Count > 0)
                                    {
                                        foreach (DataRow row in dt.Rows)
                                        {
                                            if (count >= 1)
                                            {
                                                xlsSheet.Rows.Insert(rWater + 1 + j);
                                                xlsSheetEn.Rows.Insert(rWater + 1 + j);
                                                j++;
                                            }
                                            count++;
                                            int tmp = rWater + j;

                                            string DateFrom = Func.ParseString(row["DateFrom"]);
                                            string DateTo = Func.ParseString(row["DateTo"]);

                                            string FromIndex = Func.ParseString(row["FromIndex"]);
                                            string ToIndex = Func.ParseString(row["ToIndex"]);
                                            string OtherFee01 = Func.ParseString(row["OtherFee01"]);
                                            string OtherFee02 = Func.ParseString(row["OtherFee02"]);
                                            string Mount = Func.ParseString(row["Mount"]);

                                            xlsSheet[tmp, 1].Value = DateFrom;
                                            xlsSheet[tmp, 2].Value = DateTo;
                                            xlsSheet[tmp, 3].Value = FromIndex;
                                            xlsSheet[tmp, 4].Value = ToIndex;
                                            xlsSheet[tmp, 5].Value = Mount;
                                            xlsSheet[tmp, 6].Value = row["PriceVND"];
                                            xlsSheet[tmp, 7].Value = row["OtherFee01"];
                                            xlsSheet[tmp, 8].Value = row["VatVND"];

                                            xlsSheet[tmp, 9].Value = row["SumVND"];
                                            xlsSheet[tmp, 10].Value = row["OtherFee02"];
                                            xlsSheet[tmp, 11].Value = row["WaterPricePercent"];
                                            xlsSheet[tmp, 12].Value = row["LastPriceVND"];

                                            /////En
                                            xlsSheetEn[tmp, 1].Value = DateFrom;
                                            xlsSheetEn[tmp, 2].Value = DateTo;
                                            xlsSheetEn[tmp, 3].Value = FromIndex;
                                            xlsSheetEn[tmp, 4].Value = ToIndex;
                                            xlsSheetEn[tmp, 5].Value = Mount;
                                            xlsSheetEn[tmp, 6].Value = row["PriceVND"];
                                            xlsSheetEn[tmp, 7].Value = row["OtherFee01"];
                                            xlsSheetEn[tmp, 8].Value = row["VatVND"];

                                            xlsSheetEn[tmp, 9].Value = row["SumVND"];
                                            xlsSheetEn[tmp, 10].Value = row["OtherFee02"];
                                            xlsSheetEn[tmp, 11].Value = row["WaterPricePercent"];
                                            xlsSheetEn[tmp, 12].Value = row["LastPriceVND"];

                                            /////En
                                            for (int col = 1; col <= 12; col++)
                                            {
                                                xlsSheet[tmp, col].Style = xlstStyle;
                                                xlsSheetEn[tmp, col].Style = xlstStyle;
                                            }
                                            LastSumPriceVND[5] += Convert.ToDecimal(row["LastPriceVND"]);
                                            LastSumPriceUSD[5] += Convert.ToDecimal(row["LastPriceUSD"]);

                                            mCell = new XLCellRange(tmp, tmp, 12, 13);
                                            xlsSheet.MergedCells.Add(mCell);
                                            xlsSheetEn.MergedCells.Add(mCell);
                                        }
                                        xlsSheet[rWater + 1 + j, 12].Value = LastSumPriceVND[5];
                                        xlsSheetEn[rWater + 1 + j, 12].Value = LastSumPriceVND[5];
                                        mCell = new XLCellRange(rWater + 1 + j, rWater + 1 + j, 1, 11);
                                        xlsSheet.MergedCells.Add(mCell);
                                        xlsSheetEn.MergedCells.Add(mCell);

                                        mCell = new XLCellRange(rWater + 1 + j, rWater + 1 + j, 12, 13);
                                        xlsSheet.MergedCells.Add(mCell);
                                        xlsSheetEn.MergedCells.Add(mCell);

                                        for (int col = 1; col <= 13; col++)
                                        {
                                            xlsSheet[rWater + 1 + j, col].Style = xlstStyleSum;
                                            xlsSheetEn[rWater + 1 + j, col].Style = xlstStyleSum;
                                        }
                                        sumRow += dt.Rows.Count - 1;
                                    }
                                }
                            }

                            //Service
                            ds = new DataSet();

                            sql = string.Empty;
                            sql = " SELECT Service,dbo.fnDateTime(ServiceDateFrom) ServiceDateFrom,dbo.fnDateTime(ServiceDateTo) ServiceDateTo,PriceVND,PriceUSD,VatUSD,VatVND,Mount,Unit,SumVND,SumUSD,isnull(LastPriceVND,0) LastPriceVND,isnull(LastPriceUSD,0) LastPriceUSD";
                            sql += " FROM   PaymentService";
                            sql += " WHERE BuildingId = '" + sBuildingId + "' and CustomerId = '" + CustomerId + "' and YearMonth in (" + lsYearmonth + ")";
                            sql += " Order By ServiceDate ";

                            using (SqlCommand cm = db.CreateCommand(sql))
                            {
                                SqlDataAdapter da = new SqlDataAdapter(cm);
                                da.Fill(ds);
                                line = rService - 3 + j;
                                //Phi khác
                                XLCellRange mCell = new XLCellRange(line, line + 2, 1, 1);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line + 2, 2, 2);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line + 2, 3, 3);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line + 2, 4, 4);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 5, 5);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 6, 7);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 6, 7);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 8, 9);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 8, 9);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 10, 11);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 10, 11);
                                xlsSheet.MergedCells.Add(mCell);

                                /////En
                                mCell = new XLCellRange(line, line + 2, 1, 1);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line + 2, 2, 2);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line + 2, 3, 3);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line + 2, 4, 4);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 2, 5, 5);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 6, 7);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 6, 7);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 8, 9);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 8, 9);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line, line, 10, 11);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 10, 11);
                                xlsSheetEn.MergedCells.Add(mCell);
                                /////En
                                for (int col = 1; col < 13; col++)
                                {
                                    xlsSheet[line, col].Style = xlstStyleH;
                                    xlsSheet[line + 1, col].Style = xlstStyleH;
                                    xlsSheet[line + 2, col].Style = xlstStyleH;

                                    xlsSheetEn[line, col].Style = xlstStyleH;
                                    xlsSheetEn[line + 1, col].Style = xlstStyleH;
                                    xlsSheetEn[line + 2, col].Style = xlstStyleH;
                                }
                                mCell = new XLCellRange(line, line, 12, 13);
                                xlsSheet.MergedCells.Add(mCell);
                                xlsSheetEn.MergedCells.Add(mCell);

                                mCell = new XLCellRange(line + 1, line + 1, 12, 13);
                                xlsSheet.MergedCells.Add(mCell);
                                xlsSheetEn.MergedCells.Add(mCell);

                                if (ds != null)
                                {
                                    int count = 0;
                                    DataTable dt = ds.Tables[0];

                                    if (dt.Rows.Count > 0)
                                    {

                                        foreach (DataRow row in dt.Rows)
                                        {
                                            if (count >= 1)
                                            {
                                                xlsSheet.Rows.Insert(rService + 1 + j);
                                                xlsSheetEn.Rows.Insert(rService + 1 + j);
                                                j++;
                                            }
                                            count++;
                                            int tmp = rService + j;

                                            string Service = Func.ParseString(row["Service"]);
                                            string ServiceDateFrom = Func.ParseString(row["ServiceDateFrom"]);
                                            string ServiceDateTo = Func.ParseString(row["ServiceDateTo"]);

                                            string Mount = Func.ParseString(row["Mount"]);

                                            xlsSheet[tmp, 1].Value = Service;
                                            xlsSheet[tmp, 2].Value = Func.ParseString(row["Unit"]);
                                            xlsSheet[tmp, 3].Value = ServiceDateFrom;
                                            xlsSheet[tmp, 4].Value = ServiceDateTo;
                                            xlsSheet[tmp, 5].Value = Mount;

                                            xlsSheet[tmp, 6].Value = row["PriceUSD"];
                                            xlsSheet[tmp, 7].Value = row["PriceVND"];

                                            xlsSheet[tmp, 8].Value = row["SumUSD"];
                                            xlsSheet[tmp, 9].Value = row["SumVND"];

                                            xlsSheet[tmp, 10].Value = row["VatUSD"];
                                            xlsSheet[tmp, 11].Value = row["VatVND"];

                                            xlsSheet[tmp, 12].Value = row["LastPriceUSD"];
                                            xlsSheet[tmp, 13].Value = row["LastPriceVND"];

                                            /////En
                                            xlsSheetEn[tmp, 1].Value = Service;
                                            xlsSheetEn[tmp, 2].Value = Func.ParseString(row["Unit"]);
                                            xlsSheetEn[tmp, 3].Value = ServiceDateFrom;
                                            xlsSheetEn[tmp, 4].Value = ServiceDateTo;
                                            xlsSheetEn[tmp, 5].Value = Mount;

                                            xlsSheetEn[tmp, 6].Value = row["PriceUSD"];
                                            xlsSheetEn[tmp, 7].Value = row["PriceVND"];

                                            xlsSheetEn[tmp, 8].Value = row["SumUSD"];
                                            xlsSheetEn[tmp, 9].Value = row["SumVND"];

                                            xlsSheetEn[tmp, 10].Value = row["VatUSD"];
                                            xlsSheetEn[tmp, 11].Value = row["VatVND"];

                                            xlsSheetEn[tmp, 12].Value = row["LastPriceUSD"];
                                            xlsSheetEn[tmp, 13].Value = row["LastPriceVND"];
                                            /////En

                                            for (int col = 1; col <= 13; col++)
                                            {
                                                xlsSheet[tmp, col].Style = xlstStyle;
                                                xlsSheetEn[tmp, col].Style = xlstStyle;
                                            }
                                            LastSumPriceVND[6] += Convert.ToDecimal(row["LastPriceVND"]);
                                            LastSumPriceUSD[6] += Convert.ToDecimal(row["LastPriceUSD"]);
                                        }
                                        xlsSheet[rService + 1 + j, 12].Value = LastSumPriceUSD[6];
                                        xlsSheet[rService + 1 + j, 13].Value = LastSumPriceVND[6];

                                        xlsSheetEn[rService + 1 + j, 12].Value = LastSumPriceUSD[6];
                                        xlsSheetEn[rService + 1 + j, 13].Value = LastSumPriceVND[6];

                                        mCell = new XLCellRange(rService + 1 + j, rService + 1 + j, 1, 11);
                                        xlsSheet.MergedCells.Add(mCell);
                                        xlsSheetEn.MergedCells.Add(mCell);

                                        for (int col = 1; col <= 13; col++)
                                        {
                                            xlsSheet[rService + 1 + j, col].Style = xlstStyleSum;
                                            xlsSheetEn[rService + 1 + j, col].Style = xlstStyleSum;
                                        }
                                        sumRow += dt.Rows.Count - 1;
                                    }
                                }
                            }

                            //Paid
                            sql = "Select  *";
                            sql += " From    PaymentBillDetail";
                            sql += " Where   BuildingId = '" + sBuildingId + "' and CustomerId = '" + CustomerId + "' and YearMonth in (" + lsYearmonth + ") and YearMonth < " + maxYearMonth + "";
                            string strYearMonth = "";
                            int lineTmp = rPaid - 2 + j;

                            //Paid
                            XLCellRange mCellTmp = new XLCellRange(lineTmp, lineTmp + 1, 1, 1);
                            xlsSheet.MergedCells.Add(mCellTmp);

                            mCellTmp = new XLCellRange(lineTmp, lineTmp, 2, 3);
                            xlsSheet.MergedCells.Add(mCellTmp);

                            mCellTmp = new XLCellRange(lineTmp, lineTmp, 4, 5);
                            xlsSheet.MergedCells.Add(mCellTmp);

                            mCellTmp = new XLCellRange(lineTmp, lineTmp, 6, 7);
                            xlsSheet.MergedCells.Add(mCellTmp);

                            mCellTmp = new XLCellRange(lineTmp, lineTmp, 8, 9);
                            xlsSheet.MergedCells.Add(mCellTmp);

                            mCellTmp = new XLCellRange(lineTmp, lineTmp, 12, 13);
                            xlsSheet.MergedCells.Add(mCellTmp);

                            /////En
                            mCellTmp = new XLCellRange(lineTmp, lineTmp + 1, 1, 1);
                            xlsSheetEn.MergedCells.Add(mCellTmp);

                            mCellTmp = new XLCellRange(lineTmp, lineTmp, 2, 3);
                            xlsSheetEn.MergedCells.Add(mCellTmp);

                            mCellTmp = new XLCellRange(lineTmp, lineTmp, 4, 5);
                            xlsSheetEn.MergedCells.Add(mCellTmp);

                            mCellTmp = new XLCellRange(lineTmp, lineTmp, 6, 7);
                            xlsSheetEn.MergedCells.Add(mCellTmp);

                            mCellTmp = new XLCellRange(lineTmp, lineTmp, 8, 9);
                            xlsSheetEn.MergedCells.Add(mCellTmp);

                            mCellTmp = new XLCellRange(lineTmp, lineTmp, 12, 13);
                            xlsSheetEn.MergedCells.Add(mCellTmp);
                            /////En
                            Hashtable rowNo = new Hashtable();
                            decimal[] PaidSumVND = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 };
                            decimal[] PaidSumUSD = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 };

                            DataTable dtPaid = DbHelper.GetDataTable(sql);
                            for (int i = 0; i < dtPaid.Rows.Count; i++)
                            {
                                string PaymentType = Func.ParseString(dtPaid.Rows[i]["PaymentType"]);
                                string MoneyUSD = Func.ParseString(dtPaid.Rows[i]["MoneyUSD"]);
                                string MoneyVND = Func.ParseString(dtPaid.Rows[i]["MoneyVND"]);
                                string PaidUSD = Func.ParseString(dtPaid.Rows[i]["PaidUSD"]);
                                string PaidVND = Func.ParseString(dtPaid.Rows[i]["PaidVND"]);
                                string ExchangeType = Func.ParseString(dtPaid.Rows[i]["ExchangeType"]);
                                string YearMonth = Func.ParseString(dtPaid.Rows[i]["YearMonth"]);

                                if (!rowNo.Contains(YearMonth))
                                {
                                    if (rowNo.Count != 0)
                                    {
                                        xlsSheet.Rows.Insert(rPaid + j + 1);
                                        xlsSheetEn.Rows.Insert(rPaid + j + 1);
                                        j++;
                                    }
                                    rowNo.Add(YearMonth, j);
                                }
                                int m = Func.ParseInt(rowNo[YearMonth]);
                                strYearMonth = YearMonth;
                                decimal tmpUSD = Convert.ToDecimal(MoneyUSD) - Convert.ToDecimal(PaidUSD);
                                decimal tmpVND = Convert.ToDecimal(MoneyVND) - Convert.ToDecimal(PaidVND);

                                PaidPriceUSD += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]);
                                PaidPriceVND += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]);

                                xlsSheet[rPaid + m, 1].Value = YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4);
                                xlsSheetEn[rPaid + m, 1].Value = YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4);
                                switch (PaymentType)
                                {
                                    case "1":
                                        //Rent
                                        xlsSheet[rPaid + m, 2].Value = dtPaid.Rows[i]["PaidUSD"];
                                        xlsSheet[rPaid + m, 3].Value = dtPaid.Rows[i]["PaidVND"];

                                        xlsSheetEn[rPaid + m, 2].Value = dtPaid.Rows[i]["PaidUSD"];
                                        xlsSheetEn[rPaid + m, 3].Value = dtPaid.Rows[i]["PaidVND"];

                                        PaidSumUSD[0] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]);
                                        PaidSumVND[0] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]);

                                        break;
                                    case "2":
                                        //Manager
                                        xlsSheet[rPaid + m, 4].Value = dtPaid.Rows[i]["PaidUSD"];
                                        xlsSheet[rPaid + m, 5].Value = dtPaid.Rows[i]["PaidVND"];

                                        xlsSheetEn[rPaid + m, 4].Value = dtPaid.Rows[i]["PaidUSD"];
                                        xlsSheetEn[rPaid + m, 5].Value = dtPaid.Rows[i]["PaidVND"];

                                        PaidSumUSD[1] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]);
                                        PaidSumVND[1] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]);

                                        break;
                                    case "3":
                                        //Parking
                                        xlsSheet[rPaid + m, 6].Value = dtPaid.Rows[i]["PaidUSD"];
                                        xlsSheet[rPaid + m, 7].Value = dtPaid.Rows[i]["PaidVND"];

                                        xlsSheetEn[rPaid + m, 6].Value = dtPaid.Rows[i]["PaidUSD"];
                                        xlsSheetEn[rPaid + m, 7].Value = dtPaid.Rows[i]["PaidVND"];

                                        PaidSumUSD[2] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]);
                                        PaidSumVND[2] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]);
                                        break;
                                    case "4":
                                        //Extra
                                        xlsSheet[rPaid + m, 8].Value = dtPaid.Rows[i]["PaidUSD"];
                                        xlsSheet[rPaid + m, 9].Value = dtPaid.Rows[i]["PaidVND"];

                                        xlsSheetEn[rPaid + m, 8].Value = dtPaid.Rows[i]["PaidUSD"];
                                        xlsSheetEn[rPaid + m, 9].Value = dtPaid.Rows[i]["PaidVND"];

                                        PaidSumUSD[3] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]);
                                        PaidSumVND[3] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]);
                                        break;
                                    case "5":
                                        xlsSheet[rPaid + m, 10].Value = dtPaid.Rows[i]["PaidVND"];
                                        xlsSheetEn[rPaid + m, 10].Value = dtPaid.Rows[i]["PaidVND"];

                                        PaidSumUSD[4] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]);
                                        PaidSumVND[4] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]);
                                        break;
                                    case "6":
                                        xlsSheet[rPaid + m, 11].Value = dtPaid.Rows[i]["PaidVND"];
                                        xlsSheetEn[rPaid + m, 11].Value = dtPaid.Rows[i]["PaidVND"];

                                        PaidSumUSD[5] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]);
                                        PaidSumVND[5] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]);
                                        break;
                                    case "7":
                                        xlsSheet[rPaid + m, 12].Value = dtPaid.Rows[i]["PaidUSD"];
                                        xlsSheet[rPaid + m, 13].Value = dtPaid.Rows[i]["PaidVND"];

                                        xlsSheetEn[rPaid + m, 12].Value = dtPaid.Rows[i]["PaidUSD"];
                                        xlsSheetEn[rPaid + m, 13].Value = dtPaid.Rows[i]["PaidVND"];
                                        break;
                                    default:
                                        break;
                                }
                                for (int row = rPaid + m; row <= rPaid + 1 + j; row++)
                                {
                                    for (int col = 1; col <= 13; col++)
                                    {
                                        xlsSheet[row, col].Style = xlstStyle;
                                    }
                                }
                            }
                            lineTmp = rPaid - 2 + j;

                            xlsSheet[lineTmp + 3, 2].Value = PaidSumUSD[0];
                            xlsSheet[lineTmp + 3, 3].Value = PaidSumVND[0];
                            xlsSheet[lineTmp + 3, 4].Value = PaidSumUSD[1];
                            xlsSheet[lineTmp + 3, 5].Value = PaidSumVND[1];
                            xlsSheet[lineTmp + 3, 6].Value = PaidSumUSD[2];
                            xlsSheet[lineTmp + 3, 7].Value = PaidSumVND[2];
                            xlsSheet[lineTmp + 3, 8].Value = PaidSumUSD[3];
                            xlsSheet[lineTmp + 3, 9].Value = PaidSumVND[3];
                            xlsSheet[lineTmp + 3, 10].Value = PaidSumVND[4];
                            xlsSheet[lineTmp + 3, 11].Value = PaidSumVND[5];
                            xlsSheet[lineTmp + 3, 12].Value = PaidSumUSD[6];
                            xlsSheet[lineTmp + 3, 13].Value = PaidSumVND[6];

                            /////En
                            xlsSheetEn[lineTmp + 3, 2].Value = PaidSumUSD[0];
                            xlsSheetEn[lineTmp + 3, 3].Value = PaidSumVND[0];
                            xlsSheetEn[lineTmp + 3, 4].Value = PaidSumUSD[1];
                            xlsSheetEn[lineTmp + 3, 5].Value = PaidSumVND[1];
                            xlsSheetEn[lineTmp + 3, 6].Value = PaidSumUSD[2];
                            xlsSheetEn[lineTmp + 3, 7].Value = PaidSumVND[2];
                            xlsSheetEn[lineTmp + 3, 8].Value = PaidSumUSD[3];
                            xlsSheetEn[lineTmp + 3, 9].Value = PaidSumVND[3];
                            xlsSheetEn[lineTmp + 3, 10].Value = PaidSumVND[4];
                            xlsSheetEn[lineTmp + 3, 11].Value = PaidSumVND[5];
                            xlsSheetEn[lineTmp + 3, 12].Value = PaidSumUSD[6];
                            xlsSheetEn[lineTmp + 3, 13].Value = PaidSumVND[6];
                            /////En

                            for (int col = 1; col <= 13; col++)
                            {
                                xlsSheet[lineTmp + 3, col].Style = xlstStyleSum;
                                xlsSheetEn[lineTmp + 3, col].Style = xlstStyleSum;
                            }

                            ///////////////DEPT
                            sql = "  Select *";
                            sql += " From   v_DeptBill";
                            sql += " Where  BuildingId = '" + sBuildingId + "' and CustomerId = '" + CustomerId + "' and YearMonth not in (" + lsYearmonth + ") and YearMonth < " + maxYearMonth + "";
                            sql += " And    (DeptUsd <> 0 or DeptVnd <> 0)";
                            strYearMonth = "";
                            lineTmp = rDept - 2 + j;

                            //Paid
                            mCellTmp = new XLCellRange(lineTmp, lineTmp + 1, 1, 1);
                            xlsSheet.MergedCells.Add(mCellTmp);

                            mCellTmp = new XLCellRange(lineTmp, lineTmp, 2, 3);
                            xlsSheet.MergedCells.Add(mCellTmp);

                            mCellTmp = new XLCellRange(lineTmp, lineTmp, 4, 5);
                            xlsSheet.MergedCells.Add(mCellTmp);

                            mCellTmp = new XLCellRange(lineTmp, lineTmp, 6, 7);
                            xlsSheet.MergedCells.Add(mCellTmp);

                            mCellTmp = new XLCellRange(lineTmp, lineTmp, 8, 9);
                            xlsSheet.MergedCells.Add(mCellTmp);

                            mCellTmp = new XLCellRange(lineTmp, lineTmp, 12, 13);
                            xlsSheet.MergedCells.Add(mCellTmp);

                            //////En
                            mCellTmp = new XLCellRange(lineTmp, lineTmp + 1, 1, 1);
                            xlsSheetEn.MergedCells.Add(mCellTmp);

                            mCellTmp = new XLCellRange(lineTmp, lineTmp, 2, 3);
                            xlsSheetEn.MergedCells.Add(mCellTmp);

                            mCellTmp = new XLCellRange(lineTmp, lineTmp, 4, 5);
                            xlsSheetEn.MergedCells.Add(mCellTmp);

                            mCellTmp = new XLCellRange(lineTmp, lineTmp, 6, 7);
                            xlsSheetEn.MergedCells.Add(mCellTmp);

                            mCellTmp = new XLCellRange(lineTmp, lineTmp, 8, 9);
                            xlsSheetEn.MergedCells.Add(mCellTmp);

                            mCellTmp = new XLCellRange(lineTmp, lineTmp, 12, 13);
                            xlsSheetEn.MergedCells.Add(mCellTmp);
                            //////En
                            rowNo = new Hashtable();
                            decimal DeptPriceVND = 0;
                            decimal DeptPriceUSD = 0;

                            decimal[] DeptSumVND = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 };
                            decimal[] DeptSumUSD = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 };

                            DataTable dtDept = DbHelper.GetDataTable(sql);
                            for (int i = 0; i < dtDept.Rows.Count; i++)
                            {
                                string PaymentType = Func.ParseString(dtDept.Rows[i]["PaymentType"]);
                                string DeptUSD = Func.ParseString(dtDept.Rows[i]["DeptUSD"]);
                                string DeptVND = Func.ParseString(dtDept.Rows[i]["DeptVND"]);
                                string YearMonth = Func.ParseString(dtDept.Rows[i]["YearMonth"]);

                                if (!rowNo.Contains(YearMonth))
                                {
                                    if (rowNo.Count != 0)
                                    {
                                        xlsSheet.Rows.Insert(rDept + j + 1);
                                        xlsSheetEn.Rows.Insert(rDept + j + 1);
                                        j++;
                                    }
                                    rowNo.Add(YearMonth, j);
                                }
                                int m = Func.ParseInt(rowNo[YearMonth]);
                                strYearMonth = YearMonth;

                                DeptPriceUSD += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]);
                                DeptPriceVND += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);

                                xlsSheet[rDept + m, 1].Value = YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4);
                                xlsSheetEn[rDept + m, 1].Value = YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4);

                                switch (PaymentType)
                                {
                                    case "1":
                                        //Rent
                                        xlsSheet[rDept + m, 2].Value = dtDept.Rows[i]["DeptUSD"];
                                        xlsSheet[rDept + m, 3].Value = dtDept.Rows[i]["DeptVND"];

                                        xlsSheetEn[rDept + m, 2].Value = dtDept.Rows[i]["DeptUSD"];
                                        xlsSheetEn[rDept + m, 3].Value = dtDept.Rows[i]["DeptVND"];

                                        DeptSumUSD[0] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]);
                                        DeptSumVND[0] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);

                                        break;
                                    case "2":
                                        //Manager
                                        xlsSheet[rDept + m, 4].Value = dtDept.Rows[i]["DeptUSD"];
                                        xlsSheet[rDept + m, 5].Value = dtDept.Rows[i]["DeptVND"];

                                        xlsSheetEn[rDept + m, 4].Value = dtDept.Rows[i]["DeptUSD"];
                                        xlsSheetEn[rDept + m, 5].Value = dtDept.Rows[i]["DeptVND"];

                                        DeptSumUSD[1] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]);
                                        DeptSumVND[1] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);

                                        break;
                                    case "3":
                                        //Parking
                                        xlsSheet[rDept + m, 6].Value = dtDept.Rows[i]["DeptUSD"];
                                        xlsSheet[rDept + m, 7].Value = dtDept.Rows[i]["DeptVND"];

                                        xlsSheetEn[rDept + m, 6].Value = dtDept.Rows[i]["DeptUSD"];
                                        xlsSheetEn[rDept + m, 7].Value = dtDept.Rows[i]["DeptVND"];

                                        DeptSumUSD[2] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]);
                                        DeptSumVND[2] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);
                                        break;
                                    case "4":
                                        //Extra
                                        xlsSheet[rDept + m, 8].Value = dtDept.Rows[i]["DeptUSD"];
                                        xlsSheet[rDept + m, 9].Value = dtDept.Rows[i]["DeptVND"];

                                        xlsSheetEn[rDept + m, 8].Value = dtDept.Rows[i]["DeptUSD"];
                                        xlsSheetEn[rDept + m, 9].Value = dtDept.Rows[i]["DeptVND"];

                                        DeptSumUSD[3] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]);
                                        DeptSumVND[3] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);
                                        break;
                                    case "5":
                                        xlsSheet[rDept + m, 10].Value = dtDept.Rows[i]["DeptVND"];
                                        xlsSheetEn[rDept + m, 10].Value = dtDept.Rows[i]["DeptVND"];

                                        DeptSumUSD[4] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]);
                                        DeptSumVND[4] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);
                                        break;
                                    case "6":
                                        xlsSheet[rDept + m, 11].Value = dtDept.Rows[i]["DeptVND"];
                                        xlsSheetEn[rDept + m, 11].Value = dtDept.Rows[i]["DeptVND"];

                                        DeptSumUSD[5] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]);
                                        DeptSumVND[5] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);
                                        break;
                                    case "7":
                                        xlsSheet[rDept + m, 12].Value = dtDept.Rows[i]["DeptUSD"];
                                        xlsSheet[rDept + m, 13].Value = dtDept.Rows[i]["DeptVND"];

                                        xlsSheetEn[rDept + m, 12].Value = dtDept.Rows[i]["DeptUSD"];
                                        xlsSheetEn[rDept + m, 13].Value = dtDept.Rows[i]["DeptVND"];

                                        DeptSumUSD[6] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]);
                                        DeptSumVND[6] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);
                                        break;
                                    default:
                                        break;
                                }
                                for (int row = rDept + m; row <= rDept + 1 + j; row++)
                                {
                                    for (int col = 1; col <= 13; col++)
                                    {
                                        xlsSheet[row, col].Style = xlstStyle;
                                        xlsSheetEn[row, col].Style = xlstStyle;
                                    }
                                }
                            }
                            lineTmp = rDept - 2 + j;

                            xlsSheet[lineTmp + 3, 2].Value = DeptSumUSD[0];
                            xlsSheet[lineTmp + 3, 3].Value = DeptSumVND[0];
                            xlsSheet[lineTmp + 3, 4].Value = DeptSumUSD[1];
                            xlsSheet[lineTmp + 3, 5].Value = DeptSumVND[1];
                            xlsSheet[lineTmp + 3, 6].Value = DeptSumUSD[2];
                            xlsSheet[lineTmp + 3, 7].Value = DeptSumVND[2];
                            xlsSheet[lineTmp + 3, 8].Value = DeptSumUSD[3];
                            xlsSheet[lineTmp + 3, 9].Value = DeptSumVND[3];
                            xlsSheet[lineTmp + 3, 10].Value = DeptSumVND[4];
                            xlsSheet[lineTmp + 3, 11].Value = DeptSumVND[5];
                            xlsSheet[lineTmp + 3, 12].Value = DeptSumUSD[6];
                            xlsSheet[lineTmp + 3, 13].Value = DeptSumVND[6];

                            //////En
                            xlsSheetEn[lineTmp + 3, 2].Value = DeptSumUSD[0];
                            xlsSheetEn[lineTmp + 3, 3].Value = DeptSumVND[0];
                            xlsSheetEn[lineTmp + 3, 4].Value = DeptSumUSD[1];
                            xlsSheetEn[lineTmp + 3, 5].Value = DeptSumVND[1];
                            xlsSheetEn[lineTmp + 3, 6].Value = DeptSumUSD[2];
                            xlsSheetEn[lineTmp + 3, 7].Value = DeptSumVND[2];
                            xlsSheetEn[lineTmp + 3, 8].Value = DeptSumUSD[3];
                            xlsSheetEn[lineTmp + 3, 9].Value = DeptSumVND[3];
                            xlsSheetEn[lineTmp + 3, 10].Value = DeptSumVND[4];
                            xlsSheetEn[lineTmp + 3, 11].Value = DeptSumVND[5];
                            xlsSheetEn[lineTmp + 3, 12].Value = DeptSumUSD[6];
                            xlsSheetEn[lineTmp + 3, 13].Value = DeptSumVND[6];
                            //////En
                            for (int col = 1; col <= 13; col++)
                            {
                                xlsSheet[lineTmp + 3, col].Style = xlstStyleSum;
                                xlsSheetEn[lineTmp + 3, col].Style = xlstStyleSum;
                            }

                            xlsSheet[lineTmp + 3, 1].Style = xlstStyleSum;
                            xlsSheetEn[lineTmp + 3, 1].Style = xlstStyleSum;

                            decimal AllSumVND = 0;
                            decimal AllSumUSD = 0;
                            for (int i = 0; i < 7; i++)
                            {
                                AllSumVND += LastSumPriceVND[i];
                                AllSumUSD += LastSumPriceUSD[i];
                            }

                            AllSumVND -= PaidPriceVND;
                            AllSumUSD -= PaidPriceUSD;

                            AllSumVND += DeptPriceVND;
                            AllSumUSD += DeptPriceUSD;

                            xlsSheet[rSumVND + j, cSumVND].Value = Func.FormatNumber_New(AllSumUSD);
                            xlsSheet[rSumVND + j, cSumVND].Value += "(USD)";
                            xlsSheet[rSumVND + j, cSumVND + 1].Value = Func.FormatNumber_New(AllSumVND);
                            xlsSheet[rSumVND + j, cSumVND + 1].Value += "(VND)";

                            xlsSheetEn[rSumVND + j, cSumVND].Value = Func.FormatNumber_New(AllSumUSD);
                            xlsSheetEn[rSumVND + j, cSumVND].Value += "(USD)";
                            xlsSheetEn[rSumVND + j, cSumVND + 1].Value = Func.FormatNumber_New(AllSumVND);
                            xlsSheetEn[rSumVND + j, cSumVND + 1].Value += "(VND)";

                            AllSumVND += Convert.ToDecimal(AllSumUSD * Convert.ToDecimal(UsdExchange));

                            string strMoney = Func.docso(Convert.ToInt32(AllSumVND));
                            string strMoneyEn = Func.DocSo_En(Convert.ToInt32(AllSumVND));

                            xlsSheet[rContract, cContract].Value = xlsSheet[rContract, cContract].Value.ToString().Replace("{%HOP_DONG%}", String.IsNullOrEmpty(contract) ? "" : contract.Substring(1));
                            xlsSheet[rSum + j, cSum].Value = Convert.ToInt32(AllSumVND);

                            mCellTmp = new XLCellRange(rSum + j, rSum + j, cSum, cSum + 1);
                            xlsSheet.MergedCells.Add(mCellTmp);
                            xlsSheet[rSum + j, cSum].Style = xlstStyleSum;
                            xlsSheet[rSum + j, cSum + 1].Style = xlstStyleSum;
                            xlsSheet[rSumRead + j, cSumRead].Value = xlsSheet[rSumRead + j, cSumRead].Value.ToString().Replace("{%TONG_CHU%}", strMoney.ToUpper());

                            xlsSheetEn[rContract, cContract].Value = xlsSheetEn[rContract, cContract].Value.ToString().Replace("{%HOP_DONG%}", String.IsNullOrEmpty(contract) ? "" : contract.Substring(1));
                            xlsSheetEn[rSum + j, cSum].Value = Convert.ToInt32(AllSumVND);

                            mCellTmp = new XLCellRange(rSum + j, rSum + j, cSum, cSum + 1);
                            xlsSheetEn.MergedCells.Add(mCellTmp);
                            xlsSheetEn[rSum + j, cSum].Style = xlstStyleSum;
                            xlsSheetEn[rSum + j, cSum + 1].Style = xlstStyleSum;
                            xlsSheetEn[rSumRead + j, cSumRead].Value = xlsSheetEn[rSumRead + j, cSumRead].Value.ToString().Replace("{%TONG_CHU%}", strMoneyEn.ToUpper());

                            xlbBook.Save(fileNameDes);
                            xlbBook.Clear();
                            //ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true);
                        }
                    }
                }
            }
        }
Exemplo n.º 43
0
        //---------------------------------------------------------------------------------
        #region "** object model"

        /// <summary>
        /// Saves the content of a C1FlexGrid into an XLSheet.
        /// </summary>
        public static void Save(C1FlexGrid flex, XLSheet sheet)
        {
            // clear style cache if this is a new book
            if(!object.ReferenceEquals(sheet.Book, _lastBook))
            {
                _cellStyles.Clear();
                _excelStyles.Clear();
                _lastBook = sheet.Book;
            }

            // save global parameters
            sheet.DefaultRowHeight = PixelsToTwips(flex.Rows.DefaultSize);
            sheet.DefaultColumnWidth = PixelsToTwips(flex.Columns.DefaultSize);
            sheet.ShowGridLines = flex.GridLinesVisibility != GridLinesVisibility.None;
            sheet.ShowHeaders = flex.HeadersVisibility != HeadersVisibility.None;
            sheet.OutlinesBelow = flex.GroupRowPosition == GroupRowPosition.BelowData;

            // save columns
            sheet.Columns.Clear();
            foreach(Column col in flex.Columns)
            {
                dynamic c = sheet.Columns.Add();
                if(!col.Width.IsAuto)
                {
                    c.Width = PixelsToTwips(col.ActualWidth);
                }
                c.Visible = col.Visible;
                if(col.CellStyle is ExcelCellStyle)
                {
                    c.Style = GetXLStyle(flex, sheet, (ExcelCellStyle)col.CellStyle);
                }
            }

            sheet.Rows.Clear();

            //save column headers
            XLStyle headerStyle = default(XLStyle);
            headerStyle = new XLStyle(sheet.Book);
            headerStyle.Font = new XLFont("Microsoft YaHei", 10, true, false);
            headerStyle.BorderLeft = XLLineStyleEnum.Thin;
            headerStyle.BorderTop = XLLineStyleEnum.Thin;
            headerStyle.BorderRight = XLLineStyleEnum.Thin;
            headerStyle.BorderBottom = XLLineStyleEnum.Thin;

            //save column headers
            foreach(Row row in flex.ColumnHeaders.Rows)
            {
                dynamic r = sheet.Rows.Add();
                if(row.Height > -1)
                {
                    r.Height = PixelsToTwips(row.Height);
                }
                if(row.CellStyle is ExcelCellStyle)
                {
                    r.Style = GetXLStyle(flex, sheet, (ExcelCellStyle)row.CellStyle);
                }
                if(row is ExcelRow)
                {
                    r.OutlineLevel = ((ExcelRow)row).Level;
                }
                for(int c = 0; c <= flex.ColumnHeaders.Columns.Count - 1; c++)
                {
                    // save cell value
                    dynamic cell = sheet[row.Index, c];
                    string colHeader = flex.Columns[c].Header;
                    cell.Value = colHeader;

                    // make column headers bold
                    cell.Style = headerStyle;

                }
                r.Visible = row.Visible;
            }

            // save rows
            foreach(Row row in flex.Rows)
            {
                dynamic r = sheet.Rows.Add();
                if(row.Height > -1)
                {
                    r.Height = PixelsToTwips(row.Height);
                }
                if(row.CellStyle is ExcelCellStyle)
                {
                    r.Style = GetXLStyle(flex, sheet, (ExcelCellStyle)row.CellStyle);
                }
                if(row is ExcelRow)
                {
                    r.OutlineLevel = ((ExcelRow)row).Level;
                }
                r.Visible = row.Visible;
            }

            XLStyle dateTimeStyle = default(XLStyle);
            dateTimeStyle = new XLStyle(sheet.Book);
            dateTimeStyle.Font = new XLFont("Microsoft YaHei", 10, false, false);
            dateTimeStyle.Format = "yyyy/mm/dd";
            dateTimeStyle.BorderLeft = XLLineStyleEnum.Thin;
            dateTimeStyle.BorderTop = XLLineStyleEnum.Thin;
            dateTimeStyle.BorderRight = XLLineStyleEnum.Thin;
            dateTimeStyle.BorderBottom = XLLineStyleEnum.Thin;

            XLStyle normalStyle = default(XLStyle);
            normalStyle = new XLStyle(sheet.Book);
            normalStyle.Font = new XLFont("Microsoft YaHei", 10, false, false);
            normalStyle.BorderLeft = XLLineStyleEnum.Thin;
            normalStyle.BorderTop = XLLineStyleEnum.Thin;
            normalStyle.BorderRight = XLLineStyleEnum.Thin;
            normalStyle.BorderBottom = XLLineStyleEnum.Thin;

            // save cells
            for(int r = flex.ColumnHeaders.Rows.Count; r <= flex.Rows.Count; r++)
            {
                for(int c = 0; c <= flex.Columns.Count - 1; c++)
                {
                    // save cell value
                    dynamic cell = sheet[r, c];
                    dynamic obj = flex[r - 1, c];
                    if(obj is DateTime)
                    {
                        cell.Style = dateTimeStyle;
                    }
                    else
                    {
                        cell.Style = normalStyle;
                    }
                    cell.Value = obj is FrameworkElement ? 0 : obj;

                    // save cell formula and style
                    //dynamic row = flex.Rows[r - 1] as ExcelRow;
                    //if(row != null)
                    //{
                    //    // save cell formula
                    //    dynamic col = flex.Columns[c];

                    //    // save cell style
                    //    dynamic cs = row.GetCellStyle(col) as ExcelCellStyle;
                    //    if(cs != null)
                    //    {
                    //        cell.Style = GetXLStyle(flex, sheet, cs);
                    //    }
                    //}
                }
            }

            // save selection
            dynamic sel = flex.Selection;
            if(sel.IsValid)
            {
                dynamic xlSel = new XLCellRange(sheet, sel.Row, sel.Row2, sel.Column, sel.Column2);
                sheet.SelectedCells.Clear();
                sheet.SelectedCells.Add(xlSel);
            }
        }
Exemplo n.º 44
0
        /*
        Sheet[i, 1] = "电路代号;
        Sheet[i, 1] = "故障处理人员;
        Sheet[i, 1] = "故障受理人员;
        Sheet[i, 1] = "关键字;
        Sheet[i, 1] = "恢复时间;
        Sheet[i, 1] = "客户等级;
        Sheet[i, 1] = "客户名称;
        Sheet[i, 1] = "联系电话;
        Sheet[i, 1] = "派障时间;
        Sheet[i, 1] = "是否处理成功;
        Sheet[i, 1] = "是否预约;
        Sheet[i, 1] = "受理时间;
        Sheet[i, 1] = "响应及时性;
        Sheet[i, 1] = "障碍现象;
        Sheet[i, 1] = "障碍详细地址;
        Sheet[i, 1] = "障碍原因及处理结果;
        Sheet[i, 1] = "中心编号;
        Sheet[i, 1] = "总历时;

         */
        private bool WriteDataToSheet(XLSheet Sheet)
        {
            if (dic故障管理 != null && dic故障管理.Count > 0)
            {
                Sheet[0, 0].Value = "中心编号";
                Sheet[0, 1].Value = "电路代号";
                Sheet[0, 2].Value = "故障处理人员";
                Sheet[0, 3].Value = "故障受理人员";
                Sheet[0, 4].Value = "总历时";
                Sheet[0, 5].Value = "恢复时间";
                Sheet[0, 6].Value = "客户等级";
                Sheet[0, 7].Value = "客户名称";
                Sheet[0, 8].Value = "联系电话";
                Sheet[0, 9].Value = "派障时间";
                Sheet[0, 10].Value = "是否处理成功";
                Sheet[0, 11].Value = "是否预约";
                Sheet[0, 12].Value = "受理时间";
                Sheet[0, 13].Value = "响应及时性";
                Sheet[0, 14].Value = "障碍现象";
                Sheet[0, 15].Value = "障碍详细地址";
                Sheet[0, 16].Value = "障碍原因及处理结果";
                XLStyle DateTime = new XLStyle(Sheet.Book);
                DateTime.Format = "YYYY-mm-DD HH:MM:SS";
                int Index = 1;
                foreach (int i in dic故障管理.Keys)
                {
                    Sheet[Index, 0].Value = dic故障管理[i].BbasedateID;
                    Sheet[Index, 1].Value = dic故障管理[i].B电路代号;
                    Sheet[Index, 2].Value = dic故障管理[i].B故障处理人员;
                    Sheet[Index, 3].Value = dic故障管理[i].B故障受理人员;
                    Sheet[Index, 4].Value = dic故障管理[i].B总历时;
                    Sheet[Index, 5].Value = dic故障管理[i].B恢复时间;
                    Sheet[Index, 5].Style = DateTime;
                    Sheet[Index, 6].Value = dic故障管理[i].B客户等级;
                    Sheet[Index, 7].Value = dic故障管理[i].B客户名称;
                    Sheet[Index, 8].Value = dic故障管理[i].B联系电话;
                    Sheet[Index, 9].Value = dic故障管理[i].B派障时间;
                    Sheet[Index, 9].Style = DateTime;
                    Sheet[Index, 10].Value = dic故障管理[i].B是否处理成功;
                    Sheet[Index, 11].Value = dic故障管理[i].B是否预约;
                    Sheet[Index, 12].Value = dic故障管理[i].B受理时间;
                    Sheet[Index, 12].Style = DateTime;
                    Sheet[Index, 13].Value = dic故障管理[i].B响应及时性;
                    Sheet[Index, 14].Value = dic故障管理[i].B障碍现象;
                    Sheet[Index, 15].Value = dic故障管理[i].B障碍详细地址;
                    Sheet[Index, 16].Value = dic故障管理[i].B障碍原因及处理结果;
                    Index++;
                }

            }
            else
            {
                MessageBox.Show("请先查询故障后,再进行导出!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            return true;
        }
        protected void btnView_Click(object sender, EventArgs e)
        {
            int rBillNo = 0;
            int cBillNo = 1;

            int rBillDate = 0;
            int cBillDate = 10;

            int rBillMonth = 2;
            int cBillMonth = 0;

            int rContact = 5;
            int cContact = 3;

            int rCustomer = 5;
            int cCustomer = 9;

            int rContract = 7;
            int cContract = 1;

            int rRate = 11;
            int cRate = 9;

            int rRateDate = 11;
            int cRateDate = 12;

            int rRent = 15;

            int rManager = 23;

            int rParking = 31;

            int rExtra = 39;

            int rElec = 47;

            int rWater = 55;

            int rService = 63;

            int rPaid = 70;

            int rDept = 77;

            int rOffice = 88;
            int cOffice = 3;

            int rPhone = 89;
            int cPhone = 3;

            int rBank = 89;
            int cBank = 7;

            int rAccountName = 91;
            int cAccountName = 7;

            int rAccount = 92;
            int cAccount = 7;

            int rSum = 81;
            int cSum = 11;

            int rSumRead = 82;
            int cSumRead = 13;

            int check = DbHelper.GetCount("Select count(*) from PaymentBillInfo Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + lblCustomerId.Text + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'");
            if (check == 0)
            {
                mvMessage.AddError("Xin vui lòng tạo hóa đơn trước khi xem");
                return;
            }
            mvMessage.CheckRequired(txtBillDate, "Ngày xuất Hóa đơn là danh mục bắt buộc");
            mvMessage.CheckRequired(txtBillNo, "Số Hóa đơn là danh mục bắt buộc");
            mvMessage.CheckRequired(txtUsdExchange, "Tỉ giá USD-VN là danh mục bắt buộc");
            mvMessage.CheckRequired(txtUsdExchangeDate, "Ngày tỉ giá là danh mục bắt buộc");
            //ShowData(drpYear.SelectedValue + drpMonth.SelectedValue);
            C1XLBook xlbBook = new C1XLBook();
            string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\BillTongQuat.xlsx");
            if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"])))
            {
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"])));
            }

            XLStyle xlstStyle = new XLStyle(xlbBook);
            xlstStyle.AlignHorz = XLAlignHorzEnum.Center;
            xlstStyle.AlignVert = XLAlignVertEnum.Center;
            xlstStyle.WordWrap = true;
            xlstStyle.Font = new Font("", 8, FontStyle.Regular);
            xlstStyle.SetBorderColor(Color.Black);
            xlstStyle.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyle.BorderTop = XLLineStyleEnum.Thin;
            xlstStyle.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyle.BorderRight = XLLineStyleEnum.Thin;
            xlstStyle.Format = "#,##0.00_);(#,##0.00)";

            XLStyle xlstStyleH = new XLStyle(xlbBook);
            xlstStyleH.AlignHorz = XLAlignHorzEnum.Center;
            xlstStyleH.AlignVert = XLAlignVertEnum.Center;
            xlstStyleH.Font = new Font("", 8, FontStyle.Bold);
            xlstStyleH.SetBorderColor(Color.Black);
            xlstStyleH.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyleH.BorderTop = XLLineStyleEnum.Thin;
            xlstStyleH.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyleH.BorderRight = XLLineStyleEnum.Thin;
            xlstStyleH.WordWrap = true;

            XLStyle xlstStyleSum = new XLStyle(xlbBook);
            xlstStyleSum.AlignHorz = XLAlignHorzEnum.Right;
            xlstStyleSum.AlignVert = XLAlignVertEnum.Center;
            xlstStyleSum.Font = new Font("", 8, FontStyle.Bold);
            xlstStyleSum.SetBorderColor(Color.Black);
            xlstStyleSum.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyleSum.BorderTop = XLLineStyleEnum.Thin;
            xlstStyleSum.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyleSum.BorderRight = XLLineStyleEnum.Thin;
            xlstStyleSum.WordWrap = true;

            string strDT = DateTime.Now.ToString("yyyyMMddHHmmss");
            string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BillTongQuat" + strDT + ".xlsx";
            string strFilePathExport = @"../../Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + @"/BillTongQuat" + strDT + ".xlsx";

            string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath);

            //string fileNameDes = HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\TongHopDienTich" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
            File.Copy(fileName, fileNameDes);

            xlbBook.Load(fileNameDes);
            XLSheet xlsSheet = xlbBook.Sheets["TongHop"];

            //Bill No
            xlsSheet[rBillNo, cBillNo].Value = xlsSheet[rBillNo, cBillNo].Value.ToString().Replace("{%BILL_NO%}", txtBillNo.Text);

            //Ngay Thang Nam
            DateTime dtime = DateTime.Today;

            string strTmp = xlsSheet[rBillDate, cBillDate].Value.ToString().Replace("{%NGAY%}", dtime.ToString("dd"));
            strTmp = strTmp.Replace("{%THANG%}", dtime.ToString("MM"));
            xlsSheet[rBillDate, cBillDate].Value = strTmp.Replace("{%NAM%}", dtime.ToString("yyyy"));

            //Nam
            xlsSheet[rBillMonth, cBillMonth].Value = xlsSheet[rBillMonth, cBillMonth].Value.ToString().Replace("{%NAM_THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue);

            using (SqlDatabase db = new SqlDatabase())
            {
                DataSet ds = new DataSet();
                string sql = string.Empty;

                sql = " SELECT Name, ContactName";
                sql += " FROM Customer";
                sql += " WHERE CustomerId = '" + lblCustomerId.Text + "' ";

                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    if (ds != null)
                    {
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            string Name = rowType[0].ToString();
                            string ContactName = rowType[1].ToString();

                            //Customer
                            xlsSheet[rCustomer, cCustomer].Value = xlsSheet[rCustomer, cCustomer].Value.ToString().Replace("{%TEN_CONG_TY%}", Name);
                            //Contact
                            xlsSheet[rContact, cContact].Value = xlsSheet[rContact, cContact].Value.ToString().Replace("{%NGUOI_DAI_DIEN%}", ContactName);
                        }
                    }
                }
                Hashtable contractIdLst = new Hashtable();
                string contract = "";
                ds = new DataSet();
                sql = " SELECT Bank,Account,AccountName,Office,OfficeAddress,OfficePhone";
                sql += " FROM Mst_Building";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' ";
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    if (ds != null)
                    {
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            string Bank = rowType["Bank"].ToString();
                            string Account = rowType["Account"].ToString();
                            string AccountName = rowType["AccountName"].ToString();
                            string Office = rowType["Office"].ToString();
                            string OfficeAddress = rowType["OfficeAddress"].ToString();
                            string OfficePhone = rowType["OfficePhone"].ToString();

                            xlsSheet[rOffice, cOffice].Value = xlsSheet[rOffice, cOffice].Value.ToString().Replace("{%VAN_PHONG%}", Office);
                            xlsSheet[rPhone, cPhone].Value = xlsSheet[rPhone, cPhone].Value.ToString().Replace("{%DIEN_THOAI%}", OfficePhone);

                            xlsSheet[rBank, cBank].Value = xlsSheet[rBank, cBank].Value.ToString().Replace("{%NGAN_HANG%}", Bank);
                            xlsSheet[rAccountName, cAccountName].Value = xlsSheet[rAccountName, cAccountName].Value.ToString().Replace("{%TEN_TAI_KHOAN%}", AccountName);
                            xlsSheet[rAccount, cAccount].Value = xlsSheet[rAccount, cAccount].Value.ToString().Replace("{%SO_TAI_KHOAN%}", Account);
                        }
                    }
                }

                xlsSheet[rRate, cRate].Value = xlsSheet[rRate, cRate].Value.ToString().Replace("{%TI_GIA%}", txtUsdExchange.Text);
                xlsSheet[rRateDate, cRateDate].Value = xlsSheet[rRateDate, cRateDate].Value.ToString().Replace("{%NGAY_AP_DUNG%}", txtUsdExchangeDate.Text);

                //Thue phong
                ds = new DataSet();
                sql = " Select *";
                sql += " FROM PaymentRoom";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'";

                int sumRow = 0;
                int j = 0;
                decimal[] LastSumPriceVND = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 };
                decimal[] LastSumPriceUSD = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 };

                decimal PaidPriceVND = 0;
                decimal PaidPriceUSD = 0;

                int line = 0;
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    line = rRent - 3 + j;

                    XLCellRange mCell = new XLCellRange(line, line + 2, 1, 3);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 4, 5);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 4, 5);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 2, line + 2, 4, 5);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 6, 7);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 6, 7);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 8, 9);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 8, 9);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 10, 11);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 10, 11);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);

                    if (ds != null)
                    {
                        int count = 0;
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            if (count >= 1)
                            {
                                xlsSheet.Rows.Insert(rRent + j);
                                j++;

                            }
                            count++;

                            int tmp = rRent + j;

                            string ContractId = Func.ParseString(rowType["ContractId"]);
                            string YearMonth = Func.ParseString(rowType["YearMonth"]);
                            string Area = Func.ParseString(rowType["Area"]);
                            string Name = Func.ParseString(rowType["Name"]);
                            string Regional = Func.ParseString(rowType["Regional"]);
                            string Floor = Func.ParseString(rowType["Floor"]);

                            string BeginContract = Func.ParseString(rowType["BeginContract"]);

                            if (!contractIdLst.ContainsKey(ContractId + "(" + BeginContract.Substring(0, 10) + ")"))
                            {
                                contractIdLst.Add(ContractId + "(" + BeginContract.Substring(0, 10) + ")", ContractId + "(" + BeginContract.Substring(0, 10) + ")");
                                contract += ";" + ContractId + "(" + BeginContract.Substring(0, 10) + ")";
                            }

                            xlsSheet[tmp, 1].Value = Name;
                            xlsSheet[tmp, 4].Value = rowType["Area"];
                            xlsSheet[tmp, 6].Value = rowType["MonthRentPriceUSD"];
                            xlsSheet[tmp, 7].Value = rowType["MonthRentPriceVND"];

                            xlsSheet[tmp, 8].Value = rowType["MonthRentSumUSD"];
                            xlsSheet[tmp, 9].Value = rowType["MonthRentSumVND"];

                            xlsSheet[tmp, 10].Value = rowType["VatRentPriceUSD"];
                            xlsSheet[tmp, 11].Value = rowType["VatRentPriceVND"];

                            xlsSheet[tmp, 12].Value = rowType["LastRentSumUSD"];
                            xlsSheet[tmp, 13].Value = rowType["LastRentSumVND"];

                            XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3);
                            xlsSheet.MergedCells.Add(mrCell);

                            mrCell = new XLCellRange(tmp, tmp, 4, 5);
                            xlsSheet.MergedCells.Add(mrCell);

                            LastSumPriceVND[0] += Convert.ToDecimal(rowType["LastRentSumVND"]);
                            LastSumPriceUSD[0] += Convert.ToDecimal(rowType["LastRentSumUSD"]);

                        }
                        mCell = new XLCellRange(rRent + 1 + j, rRent + 1 + j, 1, 11);
                        xlsSheet.MergedCells.Add(mCell);

                        xlsSheet[rRent + 1 + j, 12].Value = LastSumPriceUSD[0];
                        xlsSheet[rRent + 1 + j, 13].Value = LastSumPriceVND[0];

                        for (int row = rRent + sumRow - 2; row <= rRent + dt.Rows.Count; row++)
                        {
                            for (int col = 1; col <= 13; col++)
                            {
                                xlsSheet[row, col].Style = xlstStyle;
                            }
                        }
                        sumRow += dt.Rows.Count - 1;

                        ////////////////////////
                        for (int col = 1; col <= 11; col++)
                        {
                            xlsSheet[rRent + 1 + j, col].Style = xlstStyleSum;
                        }
                        line = rManager - 3 + j;

                        mCell = new XLCellRange(line, line + 2, 1, 3);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line, line, 4, 5);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line + 1, line + 1, 4, 5);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line + 2, line + 2, 4, 5);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line, line, 6, 7);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line + 1, line + 1, 6, 7);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line, line, 8, 9);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line + 1, line + 1, 8, 9);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line, line, 10, 11);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line + 1, line + 1, 10, 11);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line, line, 12, 13);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line + 1, line + 1, 12, 13);
                        xlsSheet.MergedCells.Add(mCell);

                        count = 0;
                        foreach (DataRow row in dt.Rows)
                        {
                            if (count >= 1)
                            {
                                xlsSheet.Rows.Insert(rManager + j);
                                j++;

                            }
                            count++;
                            int tmp = rManager;

                            string YearMonth = Func.ParseString(row["YearMonth"]);
                            string Area = Func.ParseString(row["Area"]);
                            string Name = Func.ParseString(row["Name"]);

                            xlsSheet[tmp, 1].Value = Name;
                            xlsSheet[tmp, 4].Value = row["Area"];
                            xlsSheet[tmp, 6].Value = row["MonthManagerPriceUSD"];
                            xlsSheet[tmp, 7].Value = row["MonthManagerPriceVND"];

                            xlsSheet[tmp, 8].Value = row["MonthManagerSumUSD"];
                            xlsSheet[tmp, 9].Value = row["MonthManagerSumVND"];

                            xlsSheet[tmp, 19].Value = row["VatManagerPriceUSD"];
                            xlsSheet[tmp, 11].Value = row["VatManagerPriceVND"];

                            xlsSheet[tmp, 12].Value = row["LastManagerSumUSD"];
                            xlsSheet[tmp, 13].Value = row["LastManagerSumVND"];

                            XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3);
                            xlsSheet.MergedCells.Add(mrCell);

                            mrCell = new XLCellRange(tmp, tmp, 4, 5);
                            xlsSheet.MergedCells.Add(mrCell);

                            LastSumPriceVND[1] += Convert.ToDecimal(row["LastManagerSumVND"]);
                            LastSumPriceUSD[1] += Convert.ToDecimal(row["LastManagerSumUSD"]);
                        }
                        mCell = new XLCellRange(rManager + 1 + j, rManager + 1 + j, 1, 11);
                        xlsSheet.MergedCells.Add(mCell);

                        xlsSheet[rManager + 1 + j, 12].Value = LastSumPriceUSD[1];
                        xlsSheet[rManager + 1 + j, 13].Value = LastSumPriceVND[1];

                        for (int row = rManager + sumRow - 2; row <= rManager + sumRow + dt.Rows.Count; row++)
                        {
                            for (int col = 1; col <= 13; col++)
                            {
                                xlsSheet[row, col].Style = xlstStyle;
                            }
                        }

                        for (int col = 1; col <= 11; col++)
                        {
                            xlsSheet[rManager + 1 + j, col].Style = xlstStyleSum;
                        }
                        sumRow += dt.Rows.Count - 1;

                    }
                }

                ds = new DataSet();
                //Xuất ra toàn bộ nội dung theo Trang
                sql = " SELECT COUNT(*) AS Num, YearMonth, TariffsParkingName, PriceVND, PriceUSD, SUM(VatVND) AS VatVND,SUM(VatUSD) AS VatUSD, SUM(SumVND) AS SumVND, SUM(SumUSD) AS SumUSD, SUM(LastPriceVND) AS LastPriceVND";
                sql += "        , SUM(LastPriceUSD) AS LastPriceUSD";
                sql += " FROM         dbo.PaymentParking";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'";
                sql += " GROUP BY YearMonth, TariffsParkingName, PriceVND, PriceUSD, Vat";

                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    line = rParking - 3 + j;
                    XLCellRange mCell = new XLCellRange(line, line + 2, 1, 3);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 4, 5);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 4, 5);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 2, line + 2, 4, 5);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 6, 7);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 6, 7);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 8, 9);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 8, 9);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 10, 11);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 10, 11);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);
                    if (ds != null)
                    {
                        int count = 0;
                        DataTable dt = ds.Tables[0];

                        foreach (DataRow row in dt.Rows)
                        {
                            if (count >= 1)
                            {
                                xlsSheet.Rows.Insert(rParking + 1 + j);
                                j++;
                            }
                            count++;
                            int tmp = rParking + j;

                            string Num = Func.ParseString(row["Num"]);
                            string TariffsParkingName = Func.ParseString(row["TariffsParkingName"]);

                            xlsSheet[tmp, 1].Value = TariffsParkingName;
                            xlsSheet[tmp, 4].Value = Num;
                            xlsSheet[tmp, 6].Value = row["PriceUSD"];
                            xlsSheet[tmp, 7].Value = row["PriceVND"];

                            xlsSheet[tmp, 8].Value = row["SumUSD"];
                            xlsSheet[tmp, 9].Value = row["SumVND"];

                            xlsSheet[tmp, 10].Value = row["VatUSD"];
                            xlsSheet[tmp, 11].Value = row["VatVND"];

                            xlsSheet[tmp, 12].Value = row["LastPriceUSD"];
                            xlsSheet[tmp, 13].Value = row["LastPriceVND"];

                            XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3);
                            xlsSheet.MergedCells.Add(mrCell);

                            mrCell = new XLCellRange(tmp, tmp, 4, 5);
                            xlsSheet.MergedCells.Add(mrCell);

                            LastSumPriceVND[2] += Convert.ToDecimal(row["LastPriceVND"]);
                            LastSumPriceUSD[2] += Convert.ToDecimal(row["LastPriceUSD"]);
                        }
                        xlsSheet[rParking + 1 + j, 12].Value = LastSumPriceUSD[2];
                        xlsSheet[rParking + 1 + j, 13].Value = LastSumPriceVND[2];

                        mCell = new XLCellRange(rParking + 1 + j, rParking + 1 + j, 1, 11);
                        xlsSheet.MergedCells.Add(mCell);

                        for (int row = rParking + sumRow - 2; row <= rParking + sumRow + dt.Rows.Count; row++)
                        {
                            for (int col = 1; col <= 13; col++)
                            {
                                xlsSheet[row, col].Style = xlstStyle;
                            }
                        }

                        for (int col = 1; col <= 11; col++)
                        {
                            xlsSheet[rParking + 1 + j, col].Style = xlstStyleSum;
                        }
                        sumRow += dt.Rows.Count - 1;
                    }
                }

                //Lam ngoai gio
                ds = new DataSet();
                sql = " SELECT ExtraHour, dbo.fnDateTime(WorkingDate) WorkingDate, PriceVND,PriceUSD,VatUSD,VatVND,SumVND,SumUSD,LastPriceVND,LastPriceUSD  ";
                sql += " FROM   PaymentExtraTime";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'";

                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    line = rExtra - 3 + j;
                    //Phi dien
                    XLCellRange mCell = new XLCellRange(line, line + 2, 1, 3);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 4, 5);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 4, 5);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 2, line + 2, 4, 5);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 6, 7);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 6, 7);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 8, 9);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 8, 9);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 10, 11);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 10, 11);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);

                    if (ds != null)
                    {
                        int count = 0;
                        DataTable dt = ds.Tables[0];

                        foreach (DataRow row in dt.Rows)
                        {
                            if (count >= 1)
                            {
                                xlsSheet.Rows.Insert(rExtra + 1 + j);
                                j++;
                            }
                            count++;
                            int tmp = rExtra + j;

                            //string id = Func.ParseString(row["id"]);
                            string ExtraHour = Func.ParseString(row["ExtraHour"]);
                            string WorkingDate = Func.ParseString(row["WorkingDate"]);

                            xlsSheet[tmp, 1].Value = WorkingDate;
                            xlsSheet[tmp, 4].Value = ExtraHour;

                            xlsSheet[tmp, 6].Value = row["PriceUSD"];
                            xlsSheet[tmp, 7].Value = row["PriceVND"];

                            xlsSheet[tmp, 8].Value = row["SumUSD"];
                            xlsSheet[tmp, 9].Value = row["SumVND"];

                            xlsSheet[tmp, 10].Value = row["VatUSD"];
                            xlsSheet[tmp, 11].Value = row["VatVND"];

                            xlsSheet[tmp, 12].Value = row["LastPriceUSD"];
                            xlsSheet[tmp, 13].Value = row["LastPriceVND"];

                            XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3);
                            xlsSheet.MergedCells.Add(mrCell);

                            mrCell = new XLCellRange(tmp, tmp, 4, 5);
                            xlsSheet.MergedCells.Add(mrCell);

                            for (int col = 1; col <= 13; col++)
                            {
                                xlsSheet[tmp, col].Style = xlstStyle;
                            }
                            LastSumPriceVND[3] += Convert.ToDecimal(row["LastPriceVND"]);
                            LastSumPriceUSD[3] += Convert.ToDecimal(row["LastPriceUSD"]);
                        }
                        mCell = new XLCellRange(rExtra + 1 + j, rExtra + 1 + j, 1, 11);
                        xlsSheet.MergedCells.Add(mCell);

                        xlsSheet[rExtra + 1 + j, 12].Value = LastSumPriceUSD[3];
                        xlsSheet[rExtra + 1 + j, 13].Value = LastSumPriceVND[3];

                        for (int row = rExtra + sumRow - 2; row <= rExtra + sumRow + dt.Rows.Count; row++)
                        {
                            for (int col = 1; col <= 13; col++)
                            {
                                xlsSheet[row, col].Style = xlstStyle;
                            }
                        }

                        for (int col = 1; col <= 12; col++)
                        {
                            xlsSheet[rExtra + 1 + j, col].Style = xlstStyleSum;
                        }
                        sumRow += dt.Rows.Count - 1;
                    }
                }

                ds = new DataSet();
                //Dien
                //Xuất ra toàn bộ nội dung theo Trang
                sql = " SELECT dbo.fnDateTime(A.DateFrom) DateFrom, dbo.fnDateTime(A.DateTo) DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.OtherFee02, B.Mount, B.PriceVND, B.PriceUSD, B.SumVND, B.SumUSD, ";
                sql += "        B.VatVND, B.VatUSD, B.LastPriceVND, B.LastPriceUSD, B.Name ";
                sql += " FROM   PaymentElecWater AS A INNER JOIN ";
                sql += "        PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId";
                sql += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfWaterId = 0  and A.YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'";
                sql += " Order by A.DateFrom, B.FromIndex";

                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    line = rElec - 3 + j;
                    //Phi dien
                    XLCellRange mCell = new XLCellRange(line, line + 2, 1, 1);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line + 2, 2, 2);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 3, 3);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 4, 4);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 5, 5);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 7, 7);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 8, 8);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 9, 10);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 9, 10);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 11, 11);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);

                    if (ds != null)
                    {
                        int count = 0;
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow row in dt.Rows)
                        {
                            if (count >= 1)
                            {
                                xlsSheet.Rows.Insert(rElec + 1 + j);
                                j++;

                            }
                            count++;
                            int tmp = rElec + j;

                            string DateFrom = Func.ParseString(row["DateFrom"]);
                            string DateTo = Func.ParseString(row["DateTo"]);

                            string FromIndex = Func.ParseString(row["FromIndex"]);
                            string ToIndex = Func.ParseString(row["ToIndex"]);
                            string OtherFee01 = Func.ParseString(row["OtherFee01"]);
                            string OtherFee02 = Func.ParseString(row["OtherFee02"]);
                            string Mount = Func.ParseString(row["Mount"]);

                            xlsSheet[tmp, 1].Value = DateFrom;
                            xlsSheet[tmp, 2].Value = DateTo;
                            xlsSheet[tmp, 3].Value = FromIndex;
                            xlsSheet[tmp, 4].Value = ToIndex;
                            xlsSheet[tmp, 5].Value = OtherFee01;
                            xlsSheet[tmp, 6].Value = Mount;
                            xlsSheet[tmp, 7].Value = row["PriceVND"];
                            xlsSheet[tmp, 8].Value = row["VatVND"];

                            xlsSheet[tmp, 9].Value = row["SumVND"];
                            xlsSheet[tmp, 11].Value = row["OtherFee02"];
                            xlsSheet[tmp, 12].Value = row["LastPriceVND"];

                            mCell = new XLCellRange(tmp, tmp, 9, 10);
                            xlsSheet.MergedCells.Add(mCell);

                            mCell = new XLCellRange(tmp, tmp, 12, 13);
                            xlsSheet.MergedCells.Add(mCell);

                            for (int col = 1; col <= 12; col++)
                            {
                                xlsSheet[tmp, col].Style = xlstStyle;
                            }
                            LastSumPriceVND[4] += Convert.ToDecimal(row["LastPriceVND"]);
                            LastSumPriceUSD[4] += Convert.ToDecimal(row["LastPriceUSD"]);
                        }
                        xlsSheet[rElec + 1 + j, 12].Value = LastSumPriceVND[4];
                        mCell = new XLCellRange(rElec + 1 + j, rElec + 1 + j, 1, 11);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(rElec + 1 + j, rElec + 1 + j, 12, 13);
                        xlsSheet.MergedCells.Add(mCell);

                        for (int row = rElec + sumRow - 2; row <= rElec + sumRow + dt.Rows.Count; row++)
                        {
                            for (int col = 1; col <= 13; col++)
                            {
                                xlsSheet[row, col].Style = xlstStyle;
                            }
                        }

                        for (int col = 1; col <= 11; col++)
                        {
                            xlsSheet[rElec + 1 + j, col].Style = xlstStyleSum;
                        }
                        sumRow += dt.Rows.Count - 1;
                    }
                }

                ds = new DataSet();
                //Nuoc
                //Xuất ra toàn bộ nội dung theo Trang
                sql = " SELECT dbo.fnDateTime(A.DateFrom) DateFrom, dbo.fnDateTime(A.DateTo) DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.OtherFee02, B.Mount, B.PriceVND, B.PriceUSD, B.SumVND, B.SumUSD, ";
                sql += "        B.VatVND, B.VatUSD, B.LastPriceVND, B.LastPriceUSD, B.Name ";
                sql += " FROM   PaymentElecWater AS A INNER JOIN ";
                sql += "        PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId";
                sql += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfElecId = 0 and A.YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'";
                sql += " Order by A.DateFrom, B.FromIndex";

                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    line = rWater - 3 + j;
                    //Phi dien
                    XLCellRange mCell = new XLCellRange(line, line + 2, 1, 1);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line + 2, 2, 2);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 3, 3);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 4, 4);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 6, 6);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 7, 7);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 8, 8);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 9, 10);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 9, 10);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 11, 11);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);

                    if (ds != null)
                    {
                        int count = 0;
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow row in dt.Rows)
                        {
                            if (count >= 1)
                            {
                                xlsSheet.Rows.Insert(rWater + 1 + j);
                                j++;

                            }
                            count++;
                            int tmp = rWater + j;

                            string DateFrom = Func.ParseString(row["DateFrom"]);
                            string DateTo = Func.ParseString(row["DateTo"]);

                            string FromIndex = Func.ParseString(row["FromIndex"]);
                            string ToIndex = Func.ParseString(row["ToIndex"]);
                            string OtherFee01 = Func.ParseString(row["OtherFee01"]);
                            string OtherFee02 = Func.ParseString(row["OtherFee02"]);
                            string Mount = Func.ParseString(row["Mount"]);

                            xlsSheet[tmp, 1].Value = DateFrom;
                            xlsSheet[tmp, 2].Value = DateTo;
                            xlsSheet[tmp, 3].Value = FromIndex;
                            xlsSheet[tmp, 4].Value = ToIndex;
                            xlsSheet[tmp, 5].Value = Mount;
                            xlsSheet[tmp, 6].Value = row["PriceVND"];
                            xlsSheet[tmp, 7].Value = row["OtherFee01"];
                            xlsSheet[tmp, 8].Value = row["VatVND"];

                            xlsSheet[tmp, 9].Value = row["SumVND"];
                            xlsSheet[tmp, 11].Value = row["OtherFee02"];
                            xlsSheet[tmp, 12].Value = row["LastPriceVND"];

                            for (int col = 1; col <= 12; col++)
                            {
                                xlsSheet[tmp, col].Style = xlstStyle;
                            }
                            LastSumPriceVND[5] += Convert.ToDecimal(row["LastPriceVND"]);
                            LastSumPriceUSD[5] += Convert.ToDecimal(row["LastPriceUSD"]);

                            mCell = new XLCellRange(tmp, tmp, 9, 10);
                            xlsSheet.MergedCells.Add(mCell);

                            mCell = new XLCellRange(tmp, tmp, 12, 13);
                            xlsSheet.MergedCells.Add(mCell);
                        }
                        xlsSheet[rWater + 1 + j, 12].Value = LastSumPriceVND[5];
                        mCell = new XLCellRange(rWater + 1 + j, rWater + 1 + j, 1, 11);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(rWater + 1 + j, rWater + 1 + j, 12, 13);
                        xlsSheet.MergedCells.Add(mCell);

                        for (int row = rWater + sumRow - 2; row <= rWater + sumRow + dt.Rows.Count; row++)
                        {
                            for (int col = 1; col <= 13; col++)
                            {
                                xlsSheet[row, col].Style = xlstStyle;
                            }
                        }
                        for (int col = 1; col <= 11; col++)
                        {
                            xlsSheet[rWater + 1 + j, col].Style = xlstStyleSum;
                        }
                        sumRow += dt.Rows.Count - 1;
                    }
                }

                //Service
                ds = new DataSet();

                sql = string.Empty;
                sql = " SELECT Service,dbo.fnDateTime(ServiceDateFrom) ServiceDateFrom,dbo.fnDateTime(ServiceDateTo) ServiceDateTo,PriceVND,PriceUSD,VatUSD,VatVND,Mount,SumVND,SumUSD,LastPriceVND,LastPriceUSD ";
                sql += " FROM   PaymentService";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'";
                sql += " Order By ServiceDate ";

                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    line = rService - 3 + j;
                    //Phi khác
                    XLCellRange mCell = new XLCellRange(line, line + 2, 1, 2);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line + 2, 3, 3);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line + 2, 4, 4);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 5, 5);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 6, 7);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 6, 7);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 8, 9);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 8, 9);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 10, 11);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 10, 11);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);

                    if (ds != null)
                    {
                        int count = 0;
                        DataTable dt = ds.Tables[0];

                        foreach (DataRow row in dt.Rows)
                        {
                            if (count >= 1)
                            {
                                xlsSheet.Rows.Insert(rService + j);
                                j++;

                            }
                            count++;
                            int tmp = rService + j;

                            string Service = Func.ParseString(row["Service"]);
                            string ServiceDateFrom = Func.ParseString(row["ServiceDateFrom"]);
                            string ServiceDateTo = Func.ParseString(row["ServiceDateTo"]);

                            string Mount = Func.ParseString(row["Mount"]);

                            xlsSheet[tmp, 1].Value = Service;
                            xlsSheet[tmp, 3].Value = ServiceDateFrom;
                            xlsSheet[tmp, 4].Value = ServiceDateTo;
                            xlsSheet[tmp, 5].Value = Mount;

                            xlsSheet[tmp, 6].Value = row["PriceUSD"];
                            xlsSheet[tmp, 7].Value = row["PriceVND"];

                            xlsSheet[tmp, 8].Value = row["SumUSD"];
                            xlsSheet[tmp, 9].Value = row["SumVND"];

                            xlsSheet[tmp, 10].Value = row["VatUSD"];
                            xlsSheet[tmp, 11].Value = row["VatVND"];

                            xlsSheet[tmp, 12].Value = row["LastPriceUSD"];
                            xlsSheet[tmp, 13].Value = row["LastPriceVND"];

                            for (int col = 1; col <= 13; col++)
                            {
                                xlsSheet[tmp, col].Style = xlstStyle;
                            }
                            LastSumPriceVND[6] += Convert.ToDecimal(row["LastPriceVND"]);
                            LastSumPriceUSD[6] += Convert.ToDecimal(row["LastPriceUSD"]);
                        }
                        xlsSheet[rService + 1 + j, 12].Value = LastSumPriceUSD[6];
                        xlsSheet[rService + 1 + j, 13].Value = LastSumPriceVND[6];

                        mCell = new XLCellRange(rService + 1 + j, rService + 1 + j, 1, 11);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(rService + 1 + j, rService + 1 + j, 12, 13);
                        xlsSheet.MergedCells.Add(mCell);

                        for (int row = rService + sumRow - 2; row <= rService + sumRow + dt.Rows.Count; row++)
                        {
                            for (int col = 1; col <= 13; col++)
                            {
                                xlsSheet[row, col].Style = xlstStyle;
                            }
                        }

                        for (int col = 1; col <= 11; col++)
                        {
                            xlsSheet[rService + 1 + j, col].Style = xlstStyleSum;
                        }
                        sumRow += dt.Rows.Count - 1;

                    }
                }

                //Paid
                sql = "Select  *";
                sql += " From    PaymentBillDetail";
                sql += " Where   BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'";
                DataTable dtPaid = DbHelper.GetDataTable(sql);
                for (int i = 0; i < dtPaid.Rows.Count; i++)
                {
                    string PaymentType = Func.ParseString(dtPaid.Rows[i]["PaymentType"]);
                    string MoneyUSD = Func.ParseString(dtPaid.Rows[i]["MoneyUSD"]);
                    string MoneyVND = Func.ParseString(dtPaid.Rows[i]["MoneyVND"]);
                    string PaidUSD = Func.ParseString(dtPaid.Rows[i]["PaidUSD"]);
                    string PaidVND = Func.ParseString(dtPaid.Rows[i]["PaidVND"]);
                    string ExchangeType = Func.ParseString(dtPaid.Rows[i]["ExchangeType"]);
                    string UsdExchange = Func.ParseString(dtPaid.Rows[i]["UsdExchange"]);
                    string YearMonth = Func.ParseString(dtPaid.Rows[i]["YearMonth"]);

                    decimal tmpUSD = Convert.ToDecimal(MoneyUSD) - Convert.ToDecimal(PaidUSD);
                    decimal tmpVND = Convert.ToDecimal(MoneyVND) - Convert.ToDecimal(PaidVND);

                    PaidPriceUSD += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]);
                    PaidPriceVND += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]);

                    xlsSheet[rPaid + j, 1].Value = YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4);
                    switch (PaymentType)
                    {
                        case "1":
                            //Rent
                            xlsSheet[rPaid + 1 + j, 2].Value = dtPaid.Rows[i]["PaidUSD"];
                            xlsSheet[rPaid + 1 + j, 3].Value = dtPaid.Rows[i]["PaidVND"];
                            break;
                        case "2":
                            //Manager
                            xlsSheet[rPaid + 1 + j, 4].Value = dtPaid.Rows[i]["PaidUSD"];
                            xlsSheet[rPaid + 1 + j, 5].Value = dtPaid.Rows[i]["PaidVND"];
                            break;
                        case "3":
                            //Parking
                            xlsSheet[rPaid + 1 + j, 6].Value = dtPaid.Rows[i]["PaidUSD"];
                            xlsSheet[rPaid + 1 + j, 7].Value = dtPaid.Rows[i]["PaidVND"];
                            break;
                        case "4":
                            //Extra
                            xlsSheet[rPaid + 1 + j, 8].Value = dtPaid.Rows[i]["PaidUSD"];
                            xlsSheet[rPaid + 1 + j, 9].Value = dtPaid.Rows[i]["PaidVND"];
                            break;
                        case "5":
                            xlsSheet[rPaid + 1 + j, 10].Value = dtPaid.Rows[i]["PaidVND"];
                            break;
                        case "6":
                            xlsSheet[rPaid + 1 + j, 11].Value = dtPaid.Rows[i]["PaidVND"];
                            break;
                        case "7":
                            xlsSheet[rPaid + 1 + j, 12].Value = dtPaid.Rows[i]["PaidUSD"];
                            xlsSheet[rPaid + 1 + j, 13].Value = dtPaid.Rows[i]["PaidVND"];
                            break;
                        default:
                            break;
                    }
                }
                int lineTmp = rPaid - 2 + j;
                //Phi khác
                XLCellRange mCellTmp = new XLCellRange(lineTmp, lineTmp + 1, 1, 1);
                xlsSheet.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 2, 3);
                xlsSheet.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 4, 5);
                xlsSheet.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 6, 7);
                xlsSheet.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 8, 9);
                xlsSheet.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 12, 13);
                xlsSheet.MergedCells.Add(mCellTmp);
                for (int row = lineTmp; row <= rPaid + 1 + j; row++)
                {
                    for (int col = 1; col <= 13; col++)
                    {
                        xlsSheet[row, col].Style = xlstStyle;
                    }
                }

                xlsSheet[lineTmp + 3, 1].Style = xlstStyleSum;

                lineTmp = rDept - 2 + j;
                //Dept
                mCellTmp = new XLCellRange(lineTmp, lineTmp + 1, 1, 1);
                xlsSheet.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 2, 3);
                xlsSheet.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 4, 5);
                xlsSheet.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 6, 7);
                xlsSheet.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 8, 9);
                xlsSheet.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 12, 13);
                xlsSheet.MergedCells.Add(mCellTmp);

                for (int row = lineTmp; row <= rDept + 1 + j; row++)
                {
                    for (int col = 1; col <= 13; col++)
                    {
                        xlsSheet[row, col].Style = xlstStyle;
                    }
                }
                xlsSheet[lineTmp + 3, 1].Style = xlstStyleSum;

                decimal AllSumVND = 0;
                decimal AllSumUSD = 0;
                for (int i = 0; i < 7; i++)
                {
                    AllSumVND += LastSumPriceVND[i];
                    AllSumUSD += LastSumPriceUSD[i];
                }

                AllSumVND -= PaidPriceVND;
                AllSumUSD -= PaidPriceUSD;
                AllSumVND += Convert.ToDecimal(AllSumUSD * Convert.ToDecimal(txtUsdExchange.Text));

                string strMoney = Func.docso(Convert.ToInt32(AllSumVND));

                xlsSheet[rContract, cContract].Value = xlsSheet[rContract, cContract].Value.ToString().Replace("{%HOP_DONG%}", contract.Substring(1));
                xlsSheet[rSum + j, cSum].Value = Convert.ToInt32(AllSumVND);
                xlsSheet[rSumRead + j, cSumRead].Value = xlsSheet[rSumRead + j, cSumRead].Value.ToString().Replace("{%TONG_CHU%}", strMoney.ToUpper());

                xlbBook.Save(fileNameDes);
                ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true);
            }
        }
Exemplo n.º 46
0
        // convert excel styles into grid styles
        static ExcelCellStyle GetCellStyle(XLStyle x)
        {
            // look it up in the cache
            ExcelCellStyle s;
            if (_cellStyles.TryGetValue(x, out s))
            {
                return s;
            }

            // not found, create style now
            s = new ExcelCellStyle();

            // alignment
            switch (x.AlignHorz)
            {
                case XLAlignHorzEnum.Left:
                    s.HorizontalAlignment = HorizontalAlignment.Left;
                    break;
                case XLAlignHorzEnum.Center:
                    s.HorizontalAlignment = HorizontalAlignment.Center;
                    break;
                case XLAlignHorzEnum.Right:
                    s.HorizontalAlignment = HorizontalAlignment.Right;
                    break;
            }
            switch (x.AlignVert)
            {
                case XLAlignVertEnum.Top:
                    s.VerticalAlignment = VerticalAlignment.Top;
                    break;
                case XLAlignVertEnum.Center:
                    s.VerticalAlignment = VerticalAlignment.Center;
                    break;
                case XLAlignVertEnum.Bottom:
                    s.VerticalAlignment = VerticalAlignment.Bottom;
                    break;
            }
            s.TextWrapping = x.WordWrap;

            // colors
            if (x.BackPattern == XLPatternEnum.Solid && IsColorValid(x.BackColor))
            {
                s.Background = new SolidColorBrush(x.BackColor);
            }
            if (IsColorValid(x.ForeColor))
            {
                s.Foreground = new SolidColorBrush(x.ForeColor);
            }

            // font
            var font = x.Font;
            if (font != null)
            {
                s.FontFamily = new FontFamily(font.FontName);
                s.FontSize = PointsToPixels(font.FontSize);
                if (font.Bold)
                {
                    s.FontWeight = FontWeights.Bold;
                }
                if (font.Italic)
                {
                    s.FontStyle = FontStyles.Italic;
                }
                if (font.Underline != XLUnderlineStyle.None)
                {
                    s.TextDecorations = TextDecorations.Underline;
                }
            }

            // format
            if (!string.IsNullOrEmpty(x.Format))
            {
                s.Format = XLStyle.FormatXLToDotNet(x.Format);
            }

            // borders
            s.CellBorderThickness = new Thickness(
                GetBorderThickness(x.BorderLeft),
                GetBorderThickness(x.BorderTop),
                GetBorderThickness(x.BorderRight),
                GetBorderThickness(x.BorderBottom));
            s.CellBorderBrushLeft = GetBorderBrush(x.BorderColorLeft);
            s.CellBorderBrushTop = GetBorderBrush(x.BorderColorTop);
            s.CellBorderBrushRight = GetBorderBrush(x.BorderColorRight);
            s.CellBorderBrushBottom = GetBorderBrush(x.BorderColorBottom);

            // save in cache and return
            _cellStyles[x] = s;
            return s;
        }
Exemplo n.º 47
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExport_Click(object sender, EventArgs e)
        {
            string[] dateOfWeekVN = { "T2", "T3", "T4", "T5", "T6", "T7", "CN" };
            string[] dateOfWeekEN = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Sartuday", "Sunday" };

            Dictionary<string, string> dictionary = new Dictionary<string, string>();
            dictionary.Add("monday", "T2");
            dictionary.Add("tuesday", "T3");
            dictionary.Add("wednesday", "T4");
            dictionary.Add("thursday", "T5");
            dictionary.Add("friday", "T6");
            dictionary.Add("saturday", "T7");
            dictionary.Add("sunday", "CN");

            DataSet ds = new DataSet();
            string sql = string.Empty;

            sql = " SELECT *";
            sql += " FROM BD_Staff";
            sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and DelFlag <> 1 and jobtypeid = '"+ hidJobType.Value +"'";
            sql += " Order By Name";

            using (SqlDatabase db = new SqlDatabase())
            {
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    db.Close();

                    if (ds != null)
                    {
                        mvMessage.SetCompleteMessage("File CSV đã xuất thành công.");

                        C1XLBook xlbBook = new C1XLBook();
                        XLSheet xlsSheet = xlbBook.Sheets[0];
                        xlsSheet.Name = drpMonth.SelectedValue + "_" + drpYear.SelectedValue;

                        int i = 0;
                        XLCellRange mrCell = new XLCellRange(0, 0, 0, 2);
                        xlsSheet.MergedCells.Add(mrCell);

                        XLStyle xlstStyle = new XLStyle(xlbBook);
                        xlstStyle.AlignHorz = XLAlignHorzEnum.Center;
                        xlstStyle.Font = new Font("", 12, FontStyle.Bold);
                        xlstStyle.SetBorderColor(Color.Black);

                        xlsSheet[i, 0].Value = "Tháng " + drpMonth.SelectedValue + "/" + drpYear.SelectedValue;
                        xlsSheet[i, 0].Style = xlstStyle;

                        xlsSheet[i + 1, 0].Value = "STT";
                        xlsSheet[i + 1, 1].Value = "Mã Nhân Viên";
                        xlsSheet[i + 1, 2].Value = "Họ và Tên";

                        XLStyle xlstStyle01 = new XLStyle(xlbBook);
                        xlstStyle01.AlignHorz = XLAlignHorzEnum.Center;
                        xlstStyle01.Font = new Font("", 10, FontStyle.Bold);
                        xlstStyle.SetBorderColor(Color.Black);

                        for (int j = 1; j <= 31; j++)
                        {
                            xlsSheet[i, 2 + j].Value = j;
                            DateTime date = new DateTime(Func.ParseInt(drpYear.SelectedValue), Func.ParseInt(drpMonth.SelectedValue), j);
                            xlsSheet[i + 1, 2 + j].Value = dictionary[date.DayOfWeek.ToString().ToLower()];

                            xlsSheet[i, 2 + j].Style = xlstStyle01;
                            xlsSheet[i + 1, 2 + j].Style = xlstStyle01;
                            if (j == DateTime.DaysInMonth(Func.ParseInt(drpYear.SelectedValue), Func.ParseInt(drpMonth.SelectedValue)))
                            {
                                break;
                            }
                        }

                        i++;
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            int No = i;
                            i++;
                            string StaffId = rowType["StaffId"].ToString();
                            string Name = rowType["Name"].ToString();

                            xlsSheet[i, 0].Value = No;
                            xlsSheet[i, 1].Value = StaffId;
                            xlsSheet[i, 2].Value = Name;

                            xlsSheet[i, 0].Style = xlstStyle01;
                            xlsSheet[i, 1].Style = xlstStyle01;
                            xlsSheet[i, 2].Style = xlstStyle01;

                        }

                        //ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('/CSV/DownloadZipFile.aspx'," + PopupWidth + "," + PopupHeight + ",'EditFlat', true);", true);

                        //xlsSheet[i++, 0].Value = "Ghi chú:";
                        DataSet ds1 = new DataSet();
                        sql = string.Empty;

                        sql = " SELECT *";
                        sql += " FROM BD_WorkingHour";
                        sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and DelFlag <> 1 and jobtypeid = '"+ hidJobType.Value +"'";
                        sql += " Order By Name";

                        using (SqlCommand cm1 = db.CreateCommand(sql))
                        {
                            SqlDataAdapter da1 = new SqlDataAdapter(cm1);
                            da1.Fill(ds1);
                            db.Close();

                            if (ds != null)
                            {

                                xlsSheet[i++ + 1, 0].Value = "Ghi chú:";
                                DataTable dt1 = ds1.Tables[0];
                                foreach (DataRow rowType in dt1.Rows)
                                {
                                    i++;
                                    string Ma = rowType["WorkingHourId"].ToString();
                                    string Name = rowType["Name"].ToString();
                                    xlsSheet[i, 0].Value = Ma + ":";
                                    xlsSheet[i, 1].Value = Name;
                                }
                                xlsSheet[i + 1, 0].Value = "OF:";
                                xlsSheet[i + 1, 1].Value = "OF: nghỉ";
                            }
                        }
                        string dataPath = HttpContext.Current.Server.MapPath(@"\Building\Staff\DataTmp");
                        string tmpFolder = dataPath;
                        if (!Directory.Exists(tmpFolder))
                        {
                            Directory.CreateDirectory(tmpFolder);
                        }
                        string name ="KhaiBaoLichLamViec_"+ DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls";
                        string fileName = Path.Combine(tmpFolder, name);
                        xlbBook.Save(fileName);
                        //Session["ZipFilePath"] = null;
                        //Session["ZipFilePath"] = fileName;

                        ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../Staff/DataTmp/" + name + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true);

                    }
                }
            }
        }
Exemplo n.º 48
0
        protected void btnExport_Click(object sender, EventArgs e)
        {
            string yearmonth = drpYear.SelectedValue;
            string building = Func.ParseString(Session["__BUILDINGID__"]);

            DataSet ds = new DataSet();
            string sql = string.Empty;

            sql = " SELECT *";
            sql += " FROM BD_BudgetSchedule ";
            sql += " WHERE BuildingId = '" + building + "' ";
            sql += " and YearMonth = '" + yearmonth + "' ";
            sql += drpBudgetExport.SelectedValue.Equals("") ? "" : " and id ='" + drpBudgetExport.SelectedValue + "'";
            sql += " and DelFlag = 0 Order by id";

            using (SqlDatabase db = new SqlDatabase())
            {
                C1XLBook xlbBook = new C1XLBook();

                string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\NganSach.xlsx");
                if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"])))
                {
                    Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"])));
                }

                string strDT = DateTime.Now.ToString("yyyyMMddHHmmss");
                string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\NganSach" + strDT + ".xlsx";
                string strFilePathExport = @"../../Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + @"/NganSach" + strDT + ".xlsx";

                string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath);

                //string fileNameDes = HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\TongHopDienTich" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx");
                File.Copy(fileName, fileNameDes);

                xlbBook.Load(fileNameDes);

                string sheet = "NganSach";

                XLSheet xlsSheet = xlbBook.Sheets[sheet];

                string IDs = "";
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    if (ds != null)
                    {
                        xlsSheet[0, 2].Value = xlsSheet[0, 2].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + building + "'"));
                        xlsSheet[0, 2].Value = xlsSheet[0, 2].Value.ToString().Replace("{%NAM_THANG%}", "NĂM " + yearmonth);

                        int j = 7;
                        DataTable dtReport = ds.Tables[0];

                        foreach (DataRow rowType in dtReport.Rows)
                        {
                            string Budget = rowType["Budget"].ToString();
                            string id = rowType["id"].ToString();

                            IDs += ",'" + id + "'";
                            xlsSheet[2, j].Value = id;
                            xlsSheet[3, j].Value = Budget;
                            j++;
                        }
                        for (int i = j; i < j * 12; i++)
                        {
                            XLColumn col = new XLColumn();
                            col = xlsSheet.Columns[j];
                            xlsSheet.Columns.Remove(col);
                        }

                    }
                }
                if (String.IsNullOrEmpty(IDs))
                {
                    mvMessage.AddError("Hiện tại chưa có Kỳ ngân sách nào được tạo");
                    return;
                }

                string buildingId = Func.ParseString(Session["__BUILDINGID__"]);
                string sessionId = Session.SessionID;
                DbHelper.ExecuteNonQuery("Delete From BD_BudgetScheduleDetailReport where SessionId = '" + sessionId + "'");

                string[] idList = IDs.Substring(1).Split(',');
                for (int m = 0; m < idList.Length; m++)
                {
                    string sqlTmp = "Select * from BD_BudgetScheduleDetail where BuggetScheduleId in (" + idList[m] + ") and delFlag = 0 Order by Id";
                    DataTable dtTable = new DataTable();
                    dtTable.Columns.Add("SessionId", Type.GetType("System.String"));
                    dtTable.Columns.Add("BuggetScheduleId", Type.GetType("System.Int32"));
                    dtTable.Columns.Add("PaymentType", Type.GetType("System.String"));
                    dtTable.Columns.Add("PaymentId", Type.GetType("System.Int32"));
                    dtTable.Columns.Add("ParentId", Type.GetType("System.Int32"));
                    dtTable.Columns.Add("InVND", Type.GetType("System.Double"));
                    dtTable.Columns.Add("InUSD", Type.GetType("System.Decimal"));
                    dtTable.Columns.Add("OutVND", Type.GetType("System.Double"));
                    dtTable.Columns.Add("OutUSD", Type.GetType("System.Decimal"));
                    dtTable.Columns.Add("ItemLevel", Type.GetType("System.String"));

                    DataTable dt = DbHelper.GetDataTable(sqlTmp);
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (dr["ParentId"].ToString() == "0")
                        {
                            int j = 1;
                            int BuggetScheduleId = Func.ParseInt(dr["BuggetScheduleId"]);
                            string PaymentType = dr["PaymentType"].ToString();
                            int PaymentId = Func.ParseInt(dr["PaymentId"]);
                            int ParentId = Func.ParseInt(dr["ParentId"]);
                            double InVND = Func.ParseDouble(dr["InVND"]);
                            decimal InUSD = Func.ParseInt(dr["InUSD"]);
                            double OutVND = Func.ParseDouble(dr["OutVND"]);
                            decimal OutUSD = Func.ParseInt(dr["OutUSD"]);
                            string itemLevel = Func.ParseString(dr["itemLevel"]);

                            dtTable.Rows.Add(sessionId, BuggetScheduleId, PaymentType, PaymentId, ParentId, InVND, InUSD, OutVND, OutUSD, itemLevel);

                            GetChildItems(Func.ParseString(PaymentId), dt, dtTable, j);
                        }
                    }
                    using (SqlBulkCopy copy = new SqlBulkCopy(Gnt.Configuration.ApplicationConfiguration.ConnectionString))
                    {
                        copy.DestinationTableName = "BD_BudgetScheduleDetailReport";
                        copy.BatchSize = 3000;
                        copy.BulkCopyTimeout = 99999;

                        copy.ColumnMappings.Add(0, "SessionId");
                        copy.ColumnMappings.Add(1, "BuggetScheduleId");
                        copy.ColumnMappings.Add(2, "PaymentType");
                        copy.ColumnMappings.Add(3, "PaymentId");
                        copy.ColumnMappings.Add(4, "ParentId");
                        copy.ColumnMappings.Add(5, "InVND");
                        copy.ColumnMappings.Add(6, "InUSD");
                        copy.ColumnMappings.Add(7, "OutVND");
                        copy.ColumnMappings.Add(8, "OutUSD");
                        copy.ColumnMappings.Add(9, "ItemLevel");

                        copy.WriteToServer(dtTable);
                    }
                }
                ds = new DataSet();
                sql = "Select * from BD_BudgetScheduleDetailReport where SessionId = '" + sessionId + "' Order by BuggetScheduleId,Id";
                int k = 5;
                int colData = 6;
                string bsId = "";
                string[] alpha = "A. B. C. D. E. F. G. H. I. J. K. L. M. N. O. P. Q. R. S. T. U. V. W. X. Y. Z.".Split(' ');
                string[] alphaLevel2 = "I. II. III. IV. V. VI. VII. VIII. IX. X. XI. XII. XII. XIV.".Split(' ');
                string[] alphaLevel3 = "1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20.".Split(' ');
                string[] alphaLevel4 = "a. b. c. d. e. f. g. h. i. j. k. l. m. n. o. p. q. r. s. t. u. v. w.".Split(' ');
                int level1 = -1;
                int level2 = -1;
                int level3 = -1;
                int level4 = -1;
                xlsSheet.Columns[1].Width = 300;
                xlsSheet.Columns[2].Width = 300;
                xlsSheet.Columns[3].Width = 300;
                xlsSheet.Columns[4].Width = 300;
                xlsSheet.Columns[5].Width = 300;
                int lastrow = 0;
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    if (ds != null)
                    {
                        double inSumVND = 0;
                        double outSumVND = 0;
                        DataTable dtReport = ds.Tables[0];
                        foreach (DataRow rowType in dtReport.Rows)
                        {
                            XLStyle xlstStyleAll = new XLStyle(xlbBook);
                            //xlstStyleAll.AlignHorz = XLAlignHorzEnum.Left;
                            xlstStyleAll.WordWrap = false;
                            xlstStyleAll.Font = new Font("", 8, FontStyle.Regular);
                            xlstStyleAll.SetBorderColor(Color.Black);
                            xlstStyleAll.BorderBottom = XLLineStyleEnum.Thin;
                            xlstStyleAll.BorderTop = XLLineStyleEnum.Thin;
                            xlstStyleAll.BorderLeft = XLLineStyleEnum.Thin;
                            xlstStyleAll.BorderRight = XLLineStyleEnum.Thin;

                            XLStyle xlstStyleLeft = new XLStyle(xlbBook);
                            //xlstStyleLeft.AlignHorz = XLAlignHorzEnum.Left;
                            xlstStyleLeft.WordWrap = false;
                            xlstStyleLeft.Font = new Font("", 8, FontStyle.Regular);
                            xlstStyleLeft.SetBorderColor(Color.Black);
                            xlstStyleLeft.BorderBottom = XLLineStyleEnum.Thin;
                            xlstStyleLeft.BorderTop = XLLineStyleEnum.Thin;
                            xlstStyleLeft.BorderLeft = XLLineStyleEnum.Thin;

                            XLStyle xlstStyleRight = new XLStyle(xlbBook);
                            //xlstStyleRight.AlignHorz = XLAlignHorzEnum.Left;
                            xlstStyleRight.WordWrap = false;
                            xlstStyleRight.Font = new Font("", 8, FontStyle.Regular);
                            xlstStyleRight.SetBorderColor(Color.Black);
                            xlstStyleRight.BorderBottom = XLLineStyleEnum.Thin;
                            xlstStyleRight.BorderTop = XLLineStyleEnum.Thin;
                            xlstStyleRight.BorderRight = XLLineStyleEnum.Thin;

                            XLStyle xlstStyleMiddle = new XLStyle(xlbBook);
                            //xlstStyleMiddle.AlignHorz = XLAlignHorzEnum.Left;
                            xlstStyleMiddle.WordWrap = false;
                            xlstStyleMiddle.Font = new Font("", 8, FontStyle.Regular);
                            xlstStyleMiddle.SetBorderColor(Color.Black);
                            xlstStyleMiddle.BorderBottom = XLLineStyleEnum.Thin;
                            xlstStyleMiddle.BorderTop = XLLineStyleEnum.Thin;

                            xlsSheet[k, 2].Style = xlstStyleLeft;
                            xlsSheet[k, 3].Style = xlstStyleMiddle;
                            xlsSheet[k, 4].Style = xlstStyleMiddle;
                            xlsSheet[k, 5].Style = xlstStyleMiddle;
                            xlsSheet[k, 6].Style = xlstStyleRight;

                            string PaymentType = rowType["PaymentType"].ToString();
                            string InVND = rowType["InVND"].ToString();
                            string InUSD = rowType["InUSD"].ToString();
                            string OutVND = rowType["OutVND"].ToString();
                            string OutUSD = rowType["OutUSD"].ToString();
                            string PaymentId = rowType["PaymentId"].ToString();
                            int colNo = Func.ParseInt(rowType["colNo"].ToString());
                            string id = rowType["BuggetScheduleId"].ToString();
                            string ParentId = rowType["ParentId"].ToString();
                            string itemLevel = rowType["ItemLevel"].ToString();

                            if (itemLevel.Equals("0"))
                            {
                                xlstStyleAll.BackColor = Color.Orange;
                                xlstStyleLeft.BackColor = Color.Orange;
                                xlstStyleRight.BackColor = Color.Orange;
                                xlstStyleMiddle.BackColor = Color.Orange;
                            }
                            else
                            {
                                xlstStyleAll.BackColor = Color.White;
                                xlstStyleLeft.BackColor = Color.White;
                                xlstStyleRight.BackColor = Color.White;
                                xlstStyleMiddle.BackColor = Color.White;
                            }

                            if (itemLevel.Equals("0") || itemLevel.Equals("1") || itemLevel.Equals("2"))
                            {
                                xlstStyleAll.Font = new Font("", 8, FontStyle.Bold);
                                xlstStyleLeft.Font = new Font("", 8, FontStyle.Bold);
                                xlstStyleRight.Font = new Font("", 8, FontStyle.Bold);
                                xlstStyleMiddle.Font = new Font("", 8, FontStyle.Bold);
                            }
                            xlsSheet[k, colData].Style = xlstStyleAll;

                            //j += 2;
                            if (!bsId.Equals(id))
                            {
                                if (k > 5)
                                {
                                    lastrow = k;
                                    xlsSheet[k, 2].Value = alpha[level1+1];
                                    xlsSheet[k, 3].Value = "CÂN ĐỐI THU - CHI (Phần Lãi)";
                                    //xlsSheet[k, colData + 1].Value = Func.ParseDouble(InUSD);
                                    xlsSheet[k, colData].Value = Func.ParseDouble(inSumVND - outSumVND);
                                }
                                k = 5;
                                colData++;
                                bsId = id;
                                level1 = -1;
                            }
                            int col = Func.ParseInt(itemLevel) + 3;

                            if (itemLevel.Equals("0"))
                            {
                                level1++;
                                xlsSheet[k, col - 1].Value = alpha[level1];

                                level2 = -1;
                            }
                            else if (itemLevel.Equals("1"))
                            {
                                level2++;
                                xlsSheet[k, col - 1].Value = alphaLevel2[level2];

                                level3 = -1;
                            }
                            else if (itemLevel.Equals("2"))
                            {
                                level3++;
                                xlsSheet[k, col - 1].Value = alphaLevel3[level3];

                                level4 = -1;
                            }
                            else if (itemLevel.Equals("3"))
                            {
                                level4++;
                                xlsSheet[k, col - 1].Value = alphaLevel4[level4];
                            }
                            xlsSheet[k, col].Value = PaymentType;
                            //xlsSheet[k, colData + 1].Value = Func.ParseDouble(InUSD);
                            xlsSheet[k, colData].Value = Func.ParseDouble(InVND);
                            ////xlsSheet[k, colData + 3].Value = Func.ParseDouble(OutUSD);
                            ////xlsSheet[k, colData + 4].Value = Func.ParseDouble(OutVND);
                            xlsSheet[k, 0].Value = PaymentId;

                            if (PaymentId.Equals("9"))
                            {
                                inSumVND = Func.ParseDouble(InVND);
                            }
                            else if (PaymentId.Equals("10"))
                            {
                                outSumVND = Func.ParseDouble(InVND);
                            }

                            //XLStyle xlstStyleAll = new XLStyle(xlbBook);
                            //xlstStyleAll.AlignHorz = XLAlignHorzEnum.Left;
                            //xlstStyleAll.WordWrap = false;
                            //xlstStyleAll.Font = new Font("", 8, FontStyle.Regular);
                            //xlstStyleAll.SetBorderColor(Color.Black);
                            //xlstStyleAll.BorderBottom = XLLineStyleEnum.Thin;
                            //xlstStyleAll.BorderTop = XLLineStyleEnum.Thin;
                            //xlstStyleAll.BorderLeft = XLLineStyleEnum.Thin;
                            //xlstStyleAll.BorderRight = XLLineStyleEnum.Thin;

                            //XLStyle xlstStyleLeft = new XLStyle(xlbBook);
                            //xlstStyleLeft.AlignHorz = XLAlignHorzEnum.Left;
                            //xlstStyleLeft.WordWrap = false;
                            //xlstStyleLeft.Font = new Font("", 8, FontStyle.Regular);
                            //xlstStyleLeft.SetBorderColor(Color.Black);
                            //xlstStyleLeft.BorderBottom = XLLineStyleEnum.Thin;
                            //xlstStyleLeft.BorderTop = XLLineStyleEnum.Thin;
                            //xlstStyleLeft.BorderLeft = XLLineStyleEnum.Thin;

                            //XLStyle xlstStyleRight = new XLStyle(xlbBook);
                            //xlstStyleRight.AlignHorz = XLAlignHorzEnum.Left;
                            //xlstStyleRight.WordWrap = false;
                            //xlstStyleRight.Font = new Font("", 8, FontStyle.Regular);
                            //xlstStyleRight.SetBorderColor(Color.Black);
                            //xlstStyleRight.BorderBottom = XLLineStyleEnum.Thin;
                            //xlstStyleRight.BorderTop = XLLineStyleEnum.Thin;
                            //xlstStyleRight.BorderRight = XLLineStyleEnum.Thin;

                            //XLStyle xlstStyleMiddle = new XLStyle(xlbBook);
                            //xlstStyleMiddle.AlignHorz = XLAlignHorzEnum.Left;
                            //xlstStyleMiddle.WordWrap = false;
                            //xlstStyleMiddle.Font = new Font("", 8, FontStyle.Regular);
                            //xlstStyleMiddle.SetBorderColor(Color.Black);
                            //xlstStyleMiddle.BorderBottom = XLLineStyleEnum.Thin;
                            //xlstStyleMiddle.BorderTop = XLLineStyleEnum.Thin;

                            //xlsSheet[k, 2].Style = xlstStyleLeft;
                            //xlsSheet[k, 3].Style = xlstStyleMiddle;
                            //xlsSheet[k, 4].Style = xlstStyleMiddle;
                            //xlsSheet[k, 5].Style = xlstStyleMiddle;
                            //xlsSheet[k, 6].Style = xlstStyleRight;

                            //if (itemLevel.Equals("0"))
                            //{
                            //    xlstStyleAll.BackColor = Color.Orange;
                            //    xlstStyleLeft.BackColor = Color.Orange;
                            //    xlstStyleRight.BackColor = Color.Orange;
                            //    xlstStyleMiddle.BackColor = Color.Orange;
                            //}
                            //else
                            //{
                            //    xlstStyleAll.BackColor = Color.White;
                            //    xlstStyleLeft.BackColor = Color.White;
                            //    xlstStyleRight.BackColor = Color.White;
                            //    xlstStyleMiddle.BackColor = Color.White;
                            //}

                            //if (itemLevel.Equals("0") || itemLevel.Equals("1") || itemLevel.Equals("2"))
                            //{
                            //    xlstStyleAll.Font = new Font("", 8, FontStyle.Bold);
                            //    xlstStyleLeft.Font = new Font("", 8, FontStyle.Bold);
                            //    xlstStyleRight.Font = new Font("", 8, FontStyle.Bold);
                            //    xlstStyleMiddle.Font = new Font("", 8, FontStyle.Bold);
                            //}
                            xlsSheet[k, colData].Style = xlstStyleAll;
                            k++;

                            if (k == lastrow)
                            {
                                XLStyle xlstStyleLast = new XLStyle(xlbBook);
                                xlstStyleLast.WordWrap = false;
                                xlstStyleLast.Font = new Font("", 8, FontStyle.Regular);
                                xlstStyleLast.SetBorderColor(Color.Black);
                                xlstStyleLast.BorderBottom = XLLineStyleEnum.Thin;
                                xlstStyleLast.BorderTop = XLLineStyleEnum.Thin;
                                xlstStyleLast.BorderLeft = XLLineStyleEnum.Thin;
                                xlstStyleLast.BorderRight = XLLineStyleEnum.Thin;
                                xlstStyleLast.Font = new Font("", 8, FontStyle.Bold);
                                xlstStyleLast.BackColor = Color.Orange;

                                xlsSheet[k, colData].Value = Func.ParseDouble(inSumVND - outSumVND);
                                xlsSheet[k, colData].Style = xlstStyleLast;
                            }

                        }
                    }
                }

                //ds = new DataSet();
                //sql = string.Empty;

                //sql = " SELECT *";
                //sql += " FROM BD_PaymentReportMonth ";
                //sql += " WHERE BuildingId = '" + building + "' ";
                //sql += " and YearMonth = '" + yearmonth + "' order by id";

                //using (db = new SqlDatabase())
                //{
                //    using (SqlCommand cm = db.CreateCommand(sql))
                //    {
                //        SqlDataAdapter da = new SqlDataAdapter(cm);
                //        da.Fill(ds);
                //        if (ds != null)
                //        {
                //            xlbBook = new C1XLBook();

                //            fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\BaoCaoThuChiThang.xlsx");
                //            if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"])))
                //            {
                //                Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"])));
                //            }

                //            strDT = DateTime.Now.ToString("yyyyMMddHHmmss");
                //            strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BaoCaoThuChiThang" + strDT + ".xlsx";
                //            strFilePathExport = "Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/BaoCaoThuChiThang" + strDT + ".xlsx";

                //            fileNameDes = HttpContext.Current.Server.MapPath(strFilePath);

                //            //string fileNameDes = HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\TongHopDienTich" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx");
                //            File.Copy(fileName, fileNameDes);

                //            xlbBook.Load(fileNameDes);

                //            sheet = "BaoCao";

                //            xlsSheet = xlbBook.Sheets[sheet];
                //            int i = 5;

                //            xlsSheet[0, 0].Value = xlsSheet[0, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + building + "'"));
                //            xlsSheet[0, 0].Value = xlsSheet[0, 0].Value.ToString().Replace("{%NAM_THANG%}", "THÁNG" + yearmonth.Substring(4, 2) + "/" + yearmonth.Substring(0, 4));

                //            DataTable dtReport = ds.Tables[0];
                //            foreach (DataRow rowType in dtReport.Rows)
                //            {
                //                int colNo = Func.ParseInt(rowType["colNo"]);
                //                string PaymentType = rowType["PaymentType"].ToString();
                //                string InVND = rowType["InVND"].ToString();
                //                string InUSD = rowType["InUSD"].ToString();
                //                string OutVND = rowType["OutVND"].ToString();
                //                string OutUSD = rowType["OutUSD"].ToString();
                //                bool bold = rowType["bold"].ToString().Equals("1") ? true : false;

                //                XLCellRange mrCell = new XLCellRange(i, i, 0, 3);
                //                xlsSheet.MergedCells.Add(mrCell);

                //                xlsSheet[i, 0].Value = "." + " ".PadLeft(colNo * 3, ' ') + PaymentType;
                //                xlsSheet[i, 4].Value = Func.ParseDouble(InUSD);
                //                xlsSheet[i, 5].Value = Func.ParseDouble(InVND);
                //                xlsSheet[i, 6].Value = Func.ParseDouble(OutUSD);
                //                xlsSheet[i, 7].Value = Func.ParseDouble(OutVND);

                //                XLStyle xlstStyle = new XLStyle(xlbBook);
                //                xlstStyle.AlignHorz = XLAlignHorzEnum.Left;
                //                xlstStyle.WordWrap = false;
                //                xlstStyle.Font = new Font("", 8, FontStyle.Regular);
                //                xlstStyle.SetBorderColor(Color.Black);
                //                xlstStyle.BorderBottom = XLLineStyleEnum.Thin;
                //                xlstStyle.BorderTop = XLLineStyleEnum.Thin;
                //                xlstStyle.BorderLeft = XLLineStyleEnum.Thin;
                //                xlstStyle.BorderRight = XLLineStyleEnum.Thin;

                //                xlsSheet[i, 0].Style = xlstStyle;
                //                xlsSheet[i, 1].Style = xlstStyle;
                //                xlsSheet[i, 2].Style = xlstStyle;
                //                xlsSheet[i, 3].Style = xlstStyle;

                //                xlstStyle = new XLStyle(xlbBook);
                //                xlstStyle.WordWrap = false;
                //                xlstStyle.Font = new Font("", 8, FontStyle.Regular);
                //                xlstStyle.SetBorderColor(Color.Black);
                //                xlstStyle.BorderBottom = XLLineStyleEnum.Thin;
                //                xlstStyle.BorderTop = XLLineStyleEnum.Thin;
                //                xlstStyle.BorderLeft = XLLineStyleEnum.Thin;
                //                xlstStyle.BorderRight = XLLineStyleEnum.Thin;
                //                xlstStyle.AlignHorz = XLAlignHorzEnum.Center;
                //                xlsSheet[i, 4].Style = xlstStyle;
                //                xlsSheet[i, 5].Style = xlstStyle;
                //                xlsSheet[i, 6].Style = xlstStyle;
                //                xlsSheet[i, 7].Style = xlstStyle;

                //                i++;
                //            }

                //            xlbBook.Save(fileNameDes);
                //            ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true);
                //        }
                //    }
                //}

                xlbBook.Save(fileNameDes);
                ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true);

            }
        }
Exemplo n.º 49
0
        public void FullNewViewMultiBoth(string lsYearmonth)
        {
            string[] strTmpYearMonth = lsYearmonth.Split(',');
            string maxYearMonth = "";
            for (int l = 0; l < strTmpYearMonth.Length; l++)
            {
                string tmp = strTmpYearMonth[l];
                if (maxYearMonth == "")
                    maxYearMonth = tmp;
                if (maxYearMonth.CompareTo(tmp) < 0)
                    maxYearMonth = tmp;
            }

            if (String.IsNullOrEmpty(lsYearmonth))
            {
                mvMessage.AddError("Phải chọn ít nhất 1 tháng");
                return;
            }

            int rBillNo = 0;
            int cBillNo = 1;

            int rBillDate = 0;
            int cBillDate = 10;

            int rBillMonth = 2;
            int cBillMonth = 0;

            int rContact = 5;
            int cContact = 3;

            int rCustomer = 5;
            int cCustomer = 7;

            int rContract = 7;
            int cContract = 1;

            //int rRate = 11;
            //int cRate = 9;

            //int rRateDate = 11;
            //int cRateDate = 12;

            int rRent = 15;

            int rManager = 23;

            int rParking = 31;

            int rExtra = 39;

            int rElec = 47;

            int rWater = 55;

            int rService = 63;

            int rPaid = 70;

            int rDept = 77;

            int rOffice = 88;
            int cOffice = 1;

            int rPhone = 89;
            int cPhone = 1;

            int rBank = 88;
            int cBank = 7;

            int rAccountName = 89;
            int cAccountName = 7;

            int rAccount = 90;
            int cAccount = 7;

            int rSum = 81;
            int cSum = 12;

            int rSumVND = 80;
            int cSumVND = 12;

            int rSumRead = 82;

            ArrayList removeRow = new ArrayList();
            ArrayList hideRow = new ArrayList();

            int check = DbHelper.GetCount("Select count(*) from PaymentBillInfo Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + lblCustomerId.Text + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'");
            if (check == 0)
            {
                mvMessage.AddError("Xin vui lòng tạo hóa đơn trước khi xem");
                return;
            }
            mvMessage.CheckRequired(txtBillDate, "Ngày xuất Hóa đơn là danh mục bắt buộc");
            mvMessage.CheckRequired(txtBillNo, "Số Hóa đơn là danh mục bắt buộc");
            mvMessage.CheckRequired(txtUsdExchange, "Tỉ giá USD-VN là danh mục bắt buộc");
            mvMessage.CheckRequired(txtUsdExchangeDate, "Ngày tỉ giá là danh mục bắt buộc");

            xlbBook = new C1XLBook();

            string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\NewBillTongQuat.xlsx");
            if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"])))
            {
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"])));
            }

            XLStyle xlstStyleLeftCH = new XLStyle(xlbBook);
            xlstStyleLeftCH.AlignHorz = XLAlignHorzEnum.Left;
            xlstStyleLeftCH.AlignVert = XLAlignVertEnum.Center;
            xlstStyleLeftCH.Font = new Font("Times New Roman", 10, FontStyle.Bold);
            xlstStyleLeftCH.SetBorderColor(Color.Black);
            xlstStyleLeftCH.BorderTop = XLLineStyleEnum.Thin;
            xlstStyleLeftCH.WordWrap = false;

            XLStyle xlstStyleC = new XLStyle(xlbBook);
            xlstStyleC.AlignHorz = XLAlignHorzEnum.Center;
            xlstStyleC.AlignVert = XLAlignVertEnum.Center;
            xlstStyleC.WordWrap = true;
            xlstStyleC.Font = new Font("Times New Roman", 10, FontStyle.Regular);
            xlstStyleC.SetBorderColor(Color.Black);
            xlstStyleC.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyleC.BorderTop = XLLineStyleEnum.Thin;
            xlstStyleC.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyleC.BorderRight = XLLineStyleEnum.Thin;
            xlstStyleC.Format = "#,##0.00_);(#,##0.00)";

            XLStyle xlstStyleC2 = new XLStyle(xlbBook);
            xlstStyleC2.AlignHorz = XLAlignHorzEnum.Center;
            xlstStyleC2.AlignVert = XLAlignVertEnum.Center;
            xlstStyleC2.WordWrap = true;
            xlstStyleC2.Font = new Font("Times New Roman", 10, FontStyle.Regular);
            xlstStyleC2.SetBorderColor(Color.Black);
            xlstStyleC2.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyleC2.BorderTop = XLLineStyleEnum.Thin;
            xlstStyleC2.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyleC2.BorderRight = XLLineStyleEnum.Thin;
            xlstStyleC2.Format = "#,##0.00_);(#,##0.00)";

            XLStyle xlstStyleC1 = new XLStyle(xlbBook);
            xlstStyleC1.AlignHorz = XLAlignHorzEnum.Center;
            xlstStyleC1.AlignVert = XLAlignVertEnum.Center;
            xlstStyleC1.WordWrap = true;
            xlstStyleC1.Font = new Font("Times New Roman", 10, FontStyle.Regular);
            xlstStyleC1.SetBorderColor(Color.Black);
            xlstStyleC1.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyleC1.BorderTop = XLLineStyleEnum.Thin;
            xlstStyleC1.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyleC1.BorderRight = XLLineStyleEnum.Thin;
            xlstStyleC1.Format = "#,##0.0_);(#,##0.0)";

            XLStyle xlstStyleC0 = new XLStyle(xlbBook);
            xlstStyleC0.AlignHorz = XLAlignHorzEnum.Center;
            xlstStyleC0.AlignVert = XLAlignVertEnum.Center;
            xlstStyleC0.WordWrap = true;
            xlstStyleC0.Font = new Font("Times New Roman", 10, FontStyle.Regular);
            xlstStyleC0.SetBorderColor(Color.Black);
            xlstStyleC0.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyleC0.BorderTop = XLLineStyleEnum.Thin;
            xlstStyleC0.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyleC0.BorderRight = XLLineStyleEnum.Thin;
            xlstStyleC0.Format = "#,##0_);(#,##0)";

            XLStyle xlstStyleCH = new XLStyle(xlbBook);
            xlstStyleCH.AlignHorz = XLAlignHorzEnum.Center;
            xlstStyleCH.AlignVert = XLAlignVertEnum.Center;
            xlstStyleCH.Font = new Font("Times New Roman", 10, FontStyle.Bold);
            xlstStyleCH.SetBorderColor(Color.Black);
            xlstStyleCH.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyleCH.BorderTop = XLLineStyleEnum.Thin;
            xlstStyleCH.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyleCH.BorderRight = XLLineStyleEnum.Thin;
            xlstStyleCH.WordWrap = true;

            XLStyle xlstStyleCSum2 = new XLStyle(xlbBook);
            xlstStyleCSum2.AlignHorz = XLAlignHorzEnum.Center;
            xlstStyleCSum2.AlignVert = XLAlignVertEnum.Center;
            xlstStyleCSum2.Font = new Font("Times New Roman", 10, FontStyle.Bold);
            xlstStyleCSum2.SetBorderColor(Color.Black);
            xlstStyleCSum2.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyleCSum2.BorderTop = XLLineStyleEnum.Thin;
            xlstStyleCSum2.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyleCSum2.BorderRight = XLLineStyleEnum.Thin;
            xlstStyleCSum2.WordWrap = true;
            xlstStyleCSum2.Format = "#,##0.00_);(#,##0.00)";

            XLStyle xlstStyleCSum1 = new XLStyle(xlbBook);
            xlstStyleCSum1.AlignHorz = XLAlignHorzEnum.Center;
            xlstStyleCSum1.AlignVert = XLAlignVertEnum.Center;
            xlstStyleCSum1.Font = new Font("Times New Roman", 10, FontStyle.Bold);
            xlstStyleCSum1.SetBorderColor(Color.Black);
            xlstStyleCSum1.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyleCSum1.BorderTop = XLLineStyleEnum.Thin;
            xlstStyleCSum1.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyleCSum1.BorderRight = XLLineStyleEnum.Thin;
            xlstStyleCSum1.WordWrap = true;
            xlstStyleCSum1.Format = "#,##0_);(#,##0)";

            XLStyle xlstStyleCSum0 = new XLStyle(xlbBook);
            xlstStyleCSum0.AlignHorz = XLAlignHorzEnum.Center;
            xlstStyleCSum0.AlignVert = XLAlignVertEnum.Center;
            xlstStyleCSum0.Font = new Font("Times New Roman", 10, FontStyle.Bold);
            xlstStyleCSum0.SetBorderColor(Color.Black);
            xlstStyleCSum0.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyleCSum0.BorderTop = XLLineStyleEnum.Thin;
            xlstStyleCSum0.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyleCSum0.BorderRight = XLLineStyleEnum.Thin;
            xlstStyleCSum0.WordWrap = true;
            xlstStyleCSum0.Format = "#,##0_);(#,##0)";

            XLStyle xlstStyle = new XLStyle(xlbBook);
            xlstStyle.AlignHorz = XLAlignHorzEnum.Center;
            xlstStyle.AlignVert = XLAlignVertEnum.Center;
            xlstStyle.WordWrap = true;
            xlstStyle.Font = new Font("Times New Roman", 10, FontStyle.Regular);
            xlstStyle.SetBorderColor(Color.Black);
            xlstStyle.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyle.BorderTop = XLLineStyleEnum.Thin;
            xlstStyle.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyle.BorderRight = XLLineStyleEnum.Thin;
            xlstStyle.Format = "#,##0.00_);(#,##0.00)";

            XLStyle xlstStyle2 = new XLStyle(xlbBook);
            xlstStyle2.AlignHorz = XLAlignHorzEnum.Right;
            xlstStyle2.AlignVert = XLAlignVertEnum.Center;
            xlstStyle2.WordWrap = true;
            xlstStyle2.Font = new Font("Times New Roman", 10, FontStyle.Regular);
            xlstStyle2.SetBorderColor(Color.Black);
            xlstStyle2.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyle2.BorderTop = XLLineStyleEnum.Thin;
            xlstStyle2.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyle2.BorderRight = XLLineStyleEnum.Thin;
            xlstStyle2.Format = "#,##0.00_);(#,##0.00)";

            XLStyle xlstStyle1 = new XLStyle(xlbBook);
            xlstStyle1.AlignHorz = XLAlignHorzEnum.Right;
            xlstStyle1.AlignVert = XLAlignVertEnum.Center;
            xlstStyle1.WordWrap = true;
            xlstStyle1.Font = new Font("Times New Roman", 10, FontStyle.Regular);
            xlstStyle1.SetBorderColor(Color.Black);
            xlstStyle1.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyle1.BorderTop = XLLineStyleEnum.Thin;
            xlstStyle1.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyle1.BorderRight = XLLineStyleEnum.Thin;
            xlstStyle1.Format = "#,##0.0_);(#,##0.0)";

            XLStyle xlstStyle0 = new XLStyle(xlbBook);
            xlstStyle0.AlignHorz = XLAlignHorzEnum.Right;
            xlstStyle0.AlignVert = XLAlignVertEnum.Center;
            xlstStyle0.WordWrap = true;
            xlstStyle0.Font = new Font("Times New Roman", 10, FontStyle.Regular);
            xlstStyle0.SetBorderColor(Color.Black);
            xlstStyle0.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyle0.BorderTop = XLLineStyleEnum.Thin;
            xlstStyle0.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyle0.BorderRight = XLLineStyleEnum.Thin;
            xlstStyle0.Format = "#,##0_);(#,##0)";

            XLStyle xlstStyleH = new XLStyle(xlbBook);
            xlstStyleH.AlignHorz = XLAlignHorzEnum.Center;
            xlstStyleH.AlignVert = XLAlignVertEnum.Center;
            xlstStyleH.Font = new Font("Times New Roman", 10, FontStyle.Bold);
            xlstStyleH.SetBorderColor(Color.Black);
            xlstStyleH.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyleH.BorderTop = XLLineStyleEnum.Thin;
            xlstStyleH.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyleH.BorderRight = XLLineStyleEnum.Thin;
            xlstStyleH.WordWrap = true;

            XLStyle xlstStyleSum2 = new XLStyle(xlbBook);
            xlstStyleSum2.AlignHorz = XLAlignHorzEnum.Right;
            xlstStyleSum2.AlignVert = XLAlignVertEnum.Center;
            xlstStyleSum2.Font = new Font("Times New Roman", 10, FontStyle.Bold);
            xlstStyleSum2.SetBorderColor(Color.Black);
            xlstStyleSum2.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyleSum2.BorderTop = XLLineStyleEnum.Thin;
            xlstStyleSum2.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyleSum2.BorderRight = XLLineStyleEnum.Thin;
            xlstStyleSum2.WordWrap = true;
            xlstStyleSum2.Format = "#,##0.00_);(#,##0.00)";

            XLStyle xlstStyleSum1 = new XLStyle(xlbBook);
            xlstStyleSum1.AlignHorz = XLAlignHorzEnum.Right;
            xlstStyleSum1.AlignVert = XLAlignVertEnum.Center;
            xlstStyleSum1.Font = new Font("Times New Roman", 10, FontStyle.Bold);
            xlstStyleSum1.SetBorderColor(Color.Black);
            xlstStyleSum1.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyleSum1.BorderTop = XLLineStyleEnum.Thin;
            xlstStyleSum1.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyleSum1.BorderRight = XLLineStyleEnum.Thin;
            xlstStyleSum1.WordWrap = true;
            xlstStyleSum1.Format = "#,##0_);(#,##0)";

            XLStyle xlstStyleSum0 = new XLStyle(xlbBook);
            xlstStyleSum0.AlignHorz = XLAlignHorzEnum.Right;
            xlstStyleSum0.AlignVert = XLAlignVertEnum.Center;
            xlstStyleSum0.Font = new Font("Times New Roman", 10, FontStyle.Bold);
            xlstStyleSum0.SetBorderColor(Color.Black);
            xlstStyleSum0.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyleSum0.BorderTop = XLLineStyleEnum.Thin;
            xlstStyleSum0.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyleSum0.BorderRight = XLLineStyleEnum.Thin;
            xlstStyleSum0.WordWrap = true;
            xlstStyleSum0.Format = "#,##0_);(#,##0)";

            if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\Bill"))
            {
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\Bill"));
            }

            string strDT = DateTime.Now.ToString("yyyyMMddHHmmss");
            string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\Bill\Bill_" + lblCustomerId.Text + "_" + strDT + ".xlsx";
            string strFilePathExport = @"../../Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + @"/Bill/Bill_" + lblCustomerId.Text + "_" + strDT + ".xlsx";

            string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath);

            File.Copy(fileName, fileNameDes);

            xlbBook.Load(fileNameDes);
            xlsSheet = xlbBook.Sheets["TongHop"];
            xlsSheetEn = xlbBook.Sheets["TongHop_En"];

            //Bill No
            setValReplace(rBillNo, cBillNo, "{%BILL_NO%}", txtBillNo.Text);
            //Ngay Thang Nam
            DateTime dtime = DateTime.Today;

            setValReplace(rBillDate, cBillDate, "{%NGAY%}", dtime.ToString("dd"));
            setValReplace(rBillDate, cBillDate, "{%THANG%}", dtime.ToString("MM"));
            setValReplace(rBillDate, cBillDate, "{%NAM%}", dtime.ToString("yyyy"));

            //Nam
            setValReplace(rBillMonth, cBillMonth, "{%NAM_THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue);

            using (SqlDatabase db = new SqlDatabase())
            {
                DataSet ds = new DataSet();
                string sql = string.Empty;

                sql = " SELECT Name, ContactName";
                sql += " FROM Customer";
                sql += " WHERE CustomerId = '" + lblCustomerId.Text + "' ";

                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    if (ds != null)
                    {
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            string Name = rowType[0].ToString();
                            string ContactName = rowType[1].ToString();

                            //Customer
                            setValReplace(rCustomer, cCustomer, "{%TEN_CONG_TY%}", Name);
                            //Contact
                            setValReplace(rContact, cContact, "{%NGUOI_DAI_DIEN%}", ContactName);
                        }
                    }
                }
                Hashtable contractIdLst = new Hashtable();
                string contract = "";
                ds = new DataSet();
                sql = " SELECT Bank,Account,AccountName,Office,OfficeAddress,OfficePhone";
                sql += " FROM Mst_Building";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' ";
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    if (ds != null)
                    {
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            string Bank = rowType["Bank"].ToString();
                            string Account = rowType["Account"].ToString();
                            string AccountName = rowType["AccountName"].ToString();
                            string Office = rowType["Office"].ToString();
                            string OfficeAddress = rowType["OfficeAddress"].ToString();
                            string OfficePhone = rowType["OfficePhone"].ToString();

                            setVal(rOffice, 2, Office);
                            setVal(rPhone, 2, OfficePhone);

                            setVal(rBank, 10, Bank);
                            setVal(rAccountName, 10, AccountName);
                            setVal(rAccount, 10, Account);

                        }
                    }
                }

                //setVal(rRate, cRate,  xlsSheet[rRate, cRate].Value.ToString().Replace("{%TI_GIA%}", Func.FormatNumber_New(txtUsdExchange.Text)));
                //setVal(rRateDate, cRateDate,  xlsSheet[rRateDate, cRateDate].Value.ToString().Replace("{%NGAY_AP_DUNG%}", txtUsdExchangeDate.Text));

                //Thue phong
                ds = new DataSet();
                sql = " Select A.*, B.ContractDate";
                sql += " FROM PaymentRoom A, RentContract B";
                sql += " WHERE A.ContractId = B.ContractId and A.BuildingId = B.BuildingId and A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and A.YearMonth in (" + lsYearmonth + ")";
                sql += " and A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and A.YearMonth in (" + lsYearmonth + ")";

                int sumRow = 0;
                int j = 0;
                decimal[] LastSumPriceVND = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 };
                decimal[] LastSumPriceUSD = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 };

                decimal PaidPriceVND = 0;
                decimal PaidPriceUSD = 0;

                int viewNumber = 1;
                string strSum = "";

                int line = 0;
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    line = rRent - 3 + j;

                    removeRow.Add(line + 2);

                    mergeCell(line, line + 1, 1, 3);
                    mergeCell(line, line, 4, 5);
                    mergeCell(line + 1, line + 1, 4, 5);
                    mergeCell(line + 2, line + 2, 4, 5);
                    mergeCell(line, line, 6, 7);
                    mergeCell(line + 1, line + 1, 6, 7);
                    mergeCell(line, line, 8, 9);
                    mergeCell(line + 1, line + 1, 8, 9);
                    mergeCell(line, line, 10, 11);
                    mergeCell(line + 1, line + 1, 10, 11);
                    mergeCell(line, line, 12, 13);
                    mergeCell(line + 1, line + 1, 12, 13);

                    if (ds != null)
                    {
                        int count = 0;
                        DataTable dt = ds.Tables[0];
                        int k = 0;
                        if (dt.Rows.Count <= 0)
                        {
                            for (int rHideLine = 0; rHideLine < 13; rHideLine++)
                            {

                                //setHideRow(rHideLine + line - 1);
                            }
                            setVal(line - 1, 0, viewNumber + ".");
                            strSum += viewNumber + " + ";

                            viewNumber++;
                        }
                        else
                        {
                            setVal(line - 1, 0, viewNumber + ".");
                            strSum += viewNumber + " + ";

                            viewNumber++;

                            foreach (DataRow rowType in dt.Rows)
                            {
                                decimal tmp02 = Convert.ToDecimal(rowType["LastRentSumVND"]);

                                string ContractId = Func.ParseString(rowType["ContractId"]);
                                string ContractNo = Func.ParseString(rowType["ContractNo"]);
                                string YearMonth = Func.ParseString(rowType["YearMonth"]);
                                string Area = Func.ParseString(rowType["Area"]);
                                string Name = Func.ParseString(rowType["Name"]);
                                string Regional = Func.ParseString(rowType["Regional"]);
                                string Floor = Func.ParseString(rowType["Floor"]);
                                string BeginContract = Func.ParseString(rowType["ContractDate"]);

                                if (!contractIdLst.ContainsKey(ContractId + "(" + Func.FormatDMY(BeginContract) + ")"))
                                {
                                    contractIdLst.Add(ContractId + "(" + Func.FormatDMY(BeginContract) + ")", ContractNo + "(" + Func.FormatDMY(BeginContract) + ")");
                                    contract += ";" + ContractNo + "(" + Func.FormatDMY(BeginContract) + ")";
                                }
                                if (tmp02 > 0)
                                {

                                    if (count >= 1)
                                    {
                                        xlsSheet.Rows.Insert(rRent + 1 + j);
                                        xlsSheetEn.Rows.Insert(rRent + 1 + j);
                                        j++;
                                    }
                                    count++;
                                    int tmp = rRent + j;
                                    setVal(tmp, 1, YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4));
                                    setVal(tmp, 4, rowType["Area"]);
                                    setVal(tmp, 6, rowType["MonthRentPriceVND"]);
                                    setVal(tmp, 8, rowType["MonthRentSumVND"]);
                                    setVal(tmp, 10, rowType["VatRentPriceVND"]);
                                    setVal(tmp, 12, rowType["LastRentSumVND"]);

                                    mergeCell(tmp, tmp, 1, 3);
                                    mergeCell(tmp, tmp, 4, 5);
                                    mergeCell(tmp, tmp, 6, 7);
                                    mergeCell(tmp, tmp, 8, 9);
                                    mergeCell(tmp, tmp, 10, 11);
                                    mergeCell(tmp, tmp, 12, 13);

                                    mergeCell(tmp, tmp, 1, 3);
                                    mergeCell(tmp, tmp, 4, 5);

                                    for (int col = 1; col <= 13; col++)
                                    {
                                        setStyle(tmp, col, xlstStyle);

                                    }

                                    setStyle(tmp, 4, xlstStyleC1);
                                    setStyle(tmp, 6, xlstStyle0);
                                    setStyle(tmp, 8, xlstStyle0);
                                    setStyle(tmp, 10, xlstStyle0);
                                    setStyle(tmp, 12, xlstStyle0);

                                    LastSumPriceVND[0] += Convert.ToDecimal(rowType["LastRentSumVND"]);
                                }
                                else
                                {
                                    k++;
                                }
                            }
                            mergeCell(rRent + 1 + j, rRent + 1 + j, 1, 11);

                            setVal(rRent + 1 + j, 12, LastSumPriceVND[0]);

                            mergeCell(rRent + 1 + j, rRent + 1 + j, 12, 13);

                            //Format
                            setStyle(rRent + 1 + j, 12, xlstStyleSum1);
                            setStyle(rRent + 1 + j, 13, xlstStyleSum0);

                            sumRow += dt.Rows.Count - 1 - k;

                            //Phi quan ly
                            line = rManager - 3 + j;
                            setVal(line - 1, 0, viewNumber + ".");
                            strSum += viewNumber + " + ";

                            viewNumber++;

                            removeRow.Add(line + 2);

                            mergeCell(line, line + 1, 1, 3);
                            mergeCell(line, line, 4, 5);
                            mergeCell(line + 1, line + 1, 4, 5);
                            mergeCell(line + 2, line + 2, 4, 5);
                            mergeCell(line, line, 6, 7);
                            mergeCell(line + 1, line + 1, 6, 7);
                            mergeCell(line, line, 8, 9);
                            mergeCell(line + 1, line + 1, 8, 9);

                            mergeCell(line, line, 10, 11);
                            mergeCell(line + 1, line + 1, 10, 11);
                            mergeCell(line, line, 12, 13);
                            mergeCell(line + 1, line + 1, 12, 13);

                            ////En
                            k = 0;
                            count = 0;
                            foreach (DataRow row in dt.Rows)
                            {
                                decimal tmp02 = Convert.ToDecimal(row["LastManagerSumVND"]);

                                if (tmp02 > 0)
                                {

                                    if (count >= 1)
                                    {
                                        xlsSheet.Rows.Insert(rManager + 1 + j);
                                        xlsSheetEn.Rows.Insert(rManager + 1 + j);
                                        j++;
                                    }
                                    count++;
                                    int tmp = rManager + j;

                                    string YearMonth = Func.ParseString(row["YearMonth"]);
                                    string Area = Func.ParseString(row["Area"]);
                                    string Name = Func.ParseString(row["Name"]);

                                    setVal(tmp, 1, YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4));
                                    setVal(tmp, 4, row["Area"]);
                                    setVal(tmp, 6, row["MonthManagerPriceVND"]);

                                    setVal(tmp, 8, row["MonthManagerSumVND"]);

                                    setVal(tmp, 10, row["VatManagerPriceVND"]);

                                    setVal(tmp, 12, row["LastManagerSumVND"]);

                                    mergeCell(tmp, tmp, 1, 3);
                                    mergeCell(tmp, tmp, 4, 5);

                                    for (int col = 1; col <= 13; col++)
                                    {
                                        setStyle(tmp, col, xlstStyle);
                                    }
                                    setStyle(tmp, 4, xlstStyleC1);
                                    setStyle(tmp, 6, xlstStyle0);
                                    setStyle(tmp, 8, xlstStyle0);
                                    setStyle(tmp, 10, xlstStyle0);
                                    setStyle(tmp, 12, xlstStyle0);

                                    mergeCell(tmp, tmp, 1, 3);
                                    mergeCell(tmp, tmp, 4, 5);
                                    mergeCell(tmp, tmp, 6, 7);
                                    mergeCell(tmp, tmp, 8, 9);
                                    mergeCell(tmp, tmp, 10, 11);
                                    mergeCell(tmp, tmp, 12, 13);

                                    LastSumPriceVND[1] += Convert.ToDecimal(row["LastManagerSumVND"]);
                                }
                                else { k++; }
                            }
                            mergeCell(rManager + 1 + j, rManager + 1 + j, 1, 11);

                            setVal(rManager + 1 + j, 12, LastSumPriceVND[1]);

                            mergeCell(rManager + 1 + j, rManager + 1 + j, 12, 13);

                            setStyle(rManager + 1 + j, 12, xlstStyleSum0);

                            sumRow += dt.Rows.Count - 1 - k;
                        }
                    }
                    else
                    {
                        setVal(line - 1, 0, viewNumber + ".");
                        strSum += viewNumber + " + ";

                        viewNumber++;
                        for (int rRentLine = 0; rRentLine < 15; rRentLine++)
                        {
                            //setHideRow(rRentLine + rRent - 4 + line);
                        }
                    }
                }

                ds = new DataSet();
                //Xuất ra toàn bộ nội dung theo Trang
                sql = " SELECT COUNT(*) AS Num, YearMonth, TariffsParkingName, PriceVND, PriceUSD, SUM(VatVND) AS VatVND,SUM(VatUSD) AS VatUSD, SUM(SumVND) AS SumVND, SUM(SumUSD) AS SumUSD, SUM(LastPriceVND) AS LastPriceVND";
                sql += "        , SUM(LastPriceUSD) AS LastPriceUSD";
                sql += " FROM         dbo.PaymentParking";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth in (" + lsYearmonth + ")";

                sql += " GROUP BY YearMonth, TariffsParkingName, PriceVND, PriceUSD, Vat, daysParking";
                sql += " HAVING (SUM(LastPriceVND) >0 or SUM(LastPriceUSD) >0)";
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    line = rParking - 3 + j;
                    removeRow.Add(line + 2);

                    mergeCell(line, line + 1, 1, 3);
                    mergeCell(line, line, 4, 5);
                    mergeCell(line + 1, line + 1, 4, 5);
                    mergeCell(line + 2, line + 2, 4, 5);
                    mergeCell(line, line, 6, 7);
                    mergeCell(line + 1, line + 1, 6, 7);
                    mergeCell(line, line, 8, 9);
                    mergeCell(line + 1, line + 1, 8, 9);
                    mergeCell(line, line, 10, 11);
                    mergeCell(line + 1, line + 1, 10, 11);
                    mergeCell(line, line, 12, 13);
                    mergeCell(line + 1, line + 1, 12, 13);
                    if (ds != null)
                    {
                        int count = 0;
                        DataTable dt = ds.Tables[0];
                        if (dt.Rows.Count > 0)
                        {
                            setVal(line - 1, 0, viewNumber + ".");
                            strSum += viewNumber + " + ";

                            viewNumber++;

                            foreach (DataRow row in dt.Rows)
                            {
                                if (count >= 1)
                                {
                                    xlsSheet.Rows.Insert(rParking + 1 + j);
                                    xlsSheetEn.Rows.Insert(rParking + 1 + j);
                                    j++;
                                }
                                count++;
                                int tmp = rParking + j;

                                string Num = Func.ParseString(row["Num"]);
                                string TariffsParkingName = Func.ParseString(row["TariffsParkingName"]);
                                // Phi gui xe
                                setVal(tmp, 1, TariffsParkingName);
                                setVal(tmp, 4, Num);
                                setVal(tmp, 6, row["PriceVND"]);
                                setVal(tmp, 8, row["SumVND"]);
                                setVal(tmp, 10, row["VatVND"]);
                                setVal(tmp, 12, row["LastPriceVND"]);

                                mergeCell(tmp, tmp, 1, 3);
                                mergeCell(tmp, tmp, 4, 5);

                                for (int col = 1; col <= 13; col++)
                                {
                                    setStyle(tmp, col, xlstStyle);
                                }
                                setStyle(tmp, 4, xlstStyleC1);
                                setStyle(tmp, 5, xlstStyleC1);
                                setStyle(tmp, 6, xlstStyle0);
                                setStyle(tmp, 8, xlstStyle0);
                                setStyle(tmp, 10, xlstStyle0);
                                setStyle(tmp, 12, xlstStyle0);

                                mergeCell(tmp, tmp, 1, 3);
                                mergeCell(tmp, tmp, 4, 5);
                                mergeCell(tmp, tmp, 6, 7);
                                mergeCell(tmp, tmp, 8, 9);
                                mergeCell(tmp, tmp, 10, 11);
                                mergeCell(tmp, tmp, 12, 13);

                                LastSumPriceVND[2] += Convert.ToDecimal(row["LastPriceVND"]);
                            }
                            setVal(rParking + 1 + j, 12, LastSumPriceVND[2]);

                            mergeCell(rParking + 1 + j, rParking + 1 + j, 1, 11);
                            mergeCell(rParking + 1 + j, rParking + 1 + j, 12, 13);

                            setStyle(rParking + 1 + j, 12, xlstStyleSum0);
                            mergeCell(rParking + 1 + j, rParking + 1 + j, 1, 11);

                            sumRow += dt.Rows.Count - 1;
                        }
                        else
                        {
                            setVal(line - 1, 0, viewNumber + ".");
                            strSum += viewNumber + " + ";

                            viewNumber++;
                            for (int rHideLine = 0; rHideLine < 6; rHideLine++)
                            {
                                //setHideRow(rHideLine + line - 1);
                            }
                        }
                    }
                }

                ds = new DataSet();
                sql = "SELECT id";
                sql += " ,YearMonth,BuildingId,CustomerId,RoomId,ExtraHour,VAT,OtherFee01,OtherFee02";
                sql += " ,PriceUSD,PriceVND,VatUSD,VatVND,SumUSD,SumVND,IsNull(LastPriceUSD,0) LastPriceUSD      ,IsNull(LastPriceVND,0) LastPriceVND ";
                sql += " ,RentArea,dbo.fnDateTime(FromWD) BeginDate,dbo.fnDateTime(EndWD) EndDate,ExtratimeType";
                sql += " FROM PaymentExtraTimeMonth";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth in (" + lsYearmonth + ")";

                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    line = rExtra - 3 + j;
                    removeRow.Add(line + 2);

                    //Phi ngoai gio
                    mergeCell(line, line + 1, 1, 2);
                    mergeCell(line, line + 1, 4, 4);
                    mergeCell(line, line, 6, 7);
                    mergeCell(line + 1, line + 1, 6, 7);
                    mergeCell(line, line, 8, 9);
                    mergeCell(line + 1, line + 1, 8, 9);
                    mergeCell(line, line, 10, 11);
                    mergeCell(line + 1, line + 1, 10, 11);
                    mergeCell(line, line, 12, 13);
                    mergeCell(line + 1, line + 1, 12, 13);
                    /////En
                    if (ds != null)
                    {
                        int count = 0;
                        DataTable dt = ds.Tables[0];

                        if (dt.Rows.Count > 0)
                        {
                            setVal(line - 1, 0, viewNumber + ".");
                            strSum += viewNumber + " + ";

                            viewNumber++;

                            foreach (DataRow row in dt.Rows)
                            {
                                if (count >= 1)
                                {
                                    xlsSheet.Rows.Insert(rExtra + 1 + j);
                                    xlsSheetEn.Rows.Insert(rExtra + 1 + j);
                                    j++;
                                }
                                count++;
                                int tmp = rExtra + j;

                                string ExtraHour = Func.ParseString(row["ExtraHour"]);
                                string BeginDate = Func.ParseString(row["BeginDate"]);
                                string EndDate = Func.ParseString(row["EndDate"]);

                                string ExtratimeType = Func.ParseString(row["ExtratimeType"]);

                                setVal(tmp, 1, BeginDate + "~" + EndDate);
                                setVal(tmp, 3, row["RentArea"]);
                                setVal(tmp, 5, ExtraHour);

                                setVal(tmp, 4, "Diện tích");
                                if ("0".Equals(ExtratimeType))
                                {
                                    setVal(tmp, 4, "m2*h");
                                }
                                setVal(tmp, 6, row["PriceVND"]);
                                setVal(tmp, 8, row["SumVND"]);
                                setVal(tmp, 10, row["VatVND"]);
                                setVal(tmp, 12, row["LastPriceVND"]);
                                LastSumPriceVND[3] += Convert.ToDecimal(row["LastPriceVND"]);

                                mergeCell(tmp, tmp, 1, 2);

                                for (int col = 1; col <= 13; col++)
                                {
                                    setStyle(tmp, col, xlstStyle);
                                }

                                /////////////////////
                                setStyle(tmp, 4, xlstStyleC1);
                                setStyle(tmp, 5, xlstStyleC1);
                                setStyle(tmp, 6, xlstStyle0);
                                setStyle(tmp, 7, xlstStyle0);
                                setStyle(tmp, 8, xlstStyle0);
                                setStyle(tmp, 9, xlstStyle0);
                                setStyle(tmp, 10, xlstStyle0);
                                setStyle(tmp, 11, xlstStyle0);
                                setStyle(tmp, 12, xlstStyle0);
                                setStyle(tmp, 13, xlstStyle0);

                                mergeCell(tmp, tmp, 1, 3);
                                mergeCell(tmp, tmp, 6, 7);
                                mergeCell(tmp, tmp, 8, 9);
                                mergeCell(tmp, tmp, 10, 11);
                                mergeCell(tmp, tmp, 12, 13);
                            }
                        }
                        else
                        {
                            setVal(line - 1, 0, viewNumber + ".");
                            strSum += viewNumber + " + ";

                            viewNumber++;
                            for (int rHideLine = 0; rHideLine < 6; rHideLine++)
                            {
                                //setHideRow(rHideLine + line - 1);
                            }
                        }
                        mergeCell(rExtra + 1 + j, rExtra + 1 + j, 1, 11);

                        setVal(rExtra + 1 + j, 12, LastSumPriceVND[3]);
                        mergeCell(rExtra + 1 + j, rExtra + 1 + j, 12, 13);

                        setStyle(rExtra + 1 + j, 12, xlstStyleSum1);
                        setStyle(rExtra + 1 + j, 13, xlstStyleSum0);

                        sumRow += dt.Rows.Count - 1;
                    }
                }

                ds = new DataSet();
                //Dien
                //Xuất ra toàn bộ nội dung theo Trang
                sql = " SELECT dbo.fnDateTime(A.DateFrom) DateFrom, dbo.fnDateTime(A.DateTo) DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.OtherFee02, B.Mount, B.PriceVND, isnull(B.Mount,0) * isnull(B.PriceVND,0) as Sum, (isnull(B.Mount,0) * isnull(B.PriceVND,0))*isnull(A.Vat, 0)/100 as SumVAT ,B.PriceUSD, B.SumVND, B.SumUSD, ";
                sql += "        B.VatVND, B.VatUSD ,IsNull(B.LastPriceUSD,0) LastPriceUSD      ,IsNull(B.LastPriceVND,0) LastPriceVND , B.Name, B.WaterPricePercent,B.ElecPricePercent ";
                sql += " FROM   PaymentElecWater AS A INNER JOIN ";
                sql += "        PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId";
                sql += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfWaterId = 0  and A.YearMonth in (" + lsYearmonth + ")  and B.DetailType = 1";
                sql += " Order by A.DateFrom, B.FromIndex";

                bool rElecVat = true;
                bool rWaterVat = true;

                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    line = rElec - 3 + j;
                    removeRow.Add(line + 2);

                    //Phi dien
                    mergeCell(line, line + 1, 1, 1);
                    mergeCell(line, line + 1, 2, 2);
                    mergeCell(line, line, 12, 13);
                    mergeCell(line + 1, line + 1, 12, 13);
                    /////En

                    for (int col = 1; col < 13; col++)
                    {
                        setStyle(line, col, xlstStyleH);
                        setStyle(line + 1, col, xlstStyleH);
                        setStyle(line + 2, col, xlstStyleH);
                    }

                    if (ds != null)
                    {
                        int count = 0;
                        DataTable dt = ds.Tables[0];

                        if (dt.Rows.Count > 0)
                        {
                            setVal(line - 1, 0, viewNumber + ".");
                            strSum += viewNumber + " + ";

                            viewNumber++;

                            foreach (DataRow row in dt.Rows)
                            {
                                if (count >= 1)
                                {
                                    xlsSheet.Rows.Insert(rElec + 1 + j);
                                    xlsSheetEn.Rows.Insert(rElec + 1 + j);
                                    j++;

                                }
                                count++;
                                int tmp = rElec + j;

                                string DateFrom = Func.ParseString(row["DateFrom"]);
                                string DateTo = Func.ParseString(row["DateTo"]);

                                string FromIndex = Func.ParseString(row["FromIndex"]);
                                string ToIndex = Func.ParseString(row["ToIndex"]);
                                string OtherFee01 = Func.ParseString(row["OtherFee01"]);
                                string OtherFee02 = Func.ParseString(row["OtherFee02"]);
                                string Mount = Func.ParseString(row["Mount"]);
                                string ElecPricePercent = Func.ParseString(row["ElecPricePercent"]);
                                string vat = Func.ParseString(row["vat"]);

                                if (rElecVat)
                                {
                                    setValReplace(line, 9, "(%VAT)", "(" + vat.Replace(",00", "") + "%VAT)");
                                    rElecVat = false;
                                }
                                setVal(tmp, 1, DateFrom);
                                setVal(tmp, 2, DateTo);
                                setVal(tmp, 3, FromIndex);
                                setVal(tmp, 4, ToIndex);
                                setVal(tmp, 5, row["OtherFee01"]);
                                setVal(tmp, 6, Mount);
                                setVal(tmp, 7, row["PriceVND"]);
                                setVal(tmp, 8, row["Sum"]);

                                setVal(tmp, 9, row["SumVAT"]);
                                setVal(tmp, 10, row["OtherFee02"]);
                                setVal(tmp, 11, row["ElecPricePercent"]);
                                setVal(tmp, 12, row["LastPriceVND"]);

                                mergeCell(tmp, tmp, 12, 13);
                                for (int col = 1; col <= 13; col++)
                                {
                                    setStyle(tmp, col, xlstStyle);
                                }

                                /////////////////
                                setStyle(tmp, 3, xlstStyleC2);
                                setStyle(tmp, 4, xlstStyleC2);
                                setStyle(tmp, 5, xlstStyleC0);
                                setStyle(tmp, 6, xlstStyle2);
                                setStyle(tmp, 7, xlstStyle0);
                                setStyle(tmp, 8, xlstStyle0);
                                setStyle(tmp, 9, xlstStyle0);
                                setStyle(tmp, 10, xlstStyle0);
                                setStyle(tmp, 11, xlstStyle2);
                                setStyle(tmp, 12, xlstStyle0);
                            }
                            DataSet dsSum = new DataSet();
                            //Dien
                            //Xuất ra toàn bộ nội dung theo Trang
                            string sqlSum = " SELECT IsNull(A.LastPriceUSD,0) LastPriceUSD      ,IsNull(A.LastPriceVND,0) LastPriceVND  ";
                            sqlSum += " FROM   PaymentElecWater AS A ";
                            sqlSum += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfElecId > 0  and A.YearMonth in (" + lsYearmonth + ")  and A.DetailType = 1";
                            using (SqlCommand cmSum = db.CreateCommand(sqlSum))
                            {
                                SqlDataAdapter daSum = new SqlDataAdapter(cmSum);
                                daSum.Fill(dsSum);

                                if (daSum != null)
                                {
                                    DataTable dtSum = dsSum.Tables[0];
                                    if (dtSum.Rows.Count > 0)
                                    {
                                        foreach (DataRow row in dtSum.Rows)
                                        {
                                            LastSumPriceUSD[4] += Convert.ToDecimal(row["LastPriceUSD"]);
                                            LastSumPriceVND[4] += Convert.ToDecimal(row["LastPriceVND"]);
                                        }
                                    }
                                }
                            }

                            ///////////////////////////
                            setVal(rElec + 1 + j, 12, Decimal.Round(LastSumPriceVND[4], 0));
                            mergeCell(rElec + 1 + j, rElec + 1 + j, 1, 11);
                            mergeCell(rElec + 1 + j, rElec + 1 + j, 12, 13);
                            ////
                            setStyle(rElec + 1 + j, 12, xlstStyleSum0);
                            mergeCell(rElec + 1 + j, rElec + 1 + j, 1, 11);
                            mergeCell(rElec + 1 + j, rElec + 1 + j, 12, 13);

                            sumRow += dt.Rows.Count - 1;
                        }
                        else
                        {
                            setVal(line - 1, 0, viewNumber + ".");
                            strSum += viewNumber + " + ";

                            viewNumber++;
                            for (int rHideLine = 0; rHideLine < 6; rHideLine++)
                            {
                                //setHideRow(rHideLine + line - 1);
                            }
                        }
                    }
                }

                ds = new DataSet();
                //Phi Nuoc
                //Xuất ra toàn bộ nội dung theo Trang
                sql = " SELECT dbo.fnDateTime(A.DateFrom) DateFrom, dbo.fnDateTime(A.DateTo) DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.OtherFee02, B.Mount, B.PriceVND, isnull(B.Mount,0) * isnull(B.PriceVND,0) as Sum, (isnull(B.Mount,0) * isnull(B.PriceVND,0))*isnull(A.Vat, 0)/100 as SumVAT , B.PriceUSD, B.SumVND, B.SumUSD, ";
                sql += "        B.VatVND, B.VatUSD,IsNull(B.LastPriceUSD,0) LastPriceUSD,IsNull(B.LastPriceVND,0) LastPriceVND, B.Name, B.WaterPricePercent,B.ElecPricePercent  ";
                sql += " FROM   PaymentElecWater AS A INNER JOIN ";
                sql += "        PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId";
                sql += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfElecId = 0 and A.YearMonth in (" + lsYearmonth + ")  and B.DetailType = 2";
                sql += " Order by A.DateFrom, B.FromIndex";

                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    line = rWater - 3 + j;
                    removeRow.Add(line + 2);

                    //Phi nuoc
                    mergeCell(line, line + 1, 1, 1);
                    mergeCell(line, line + 1, 2, 2);
                    mergeCell(line, line, 12, 13);
                    mergeCell(line + 1, line + 1, 12, 13);

                    for (int col = 1; col < 13; col++)
                    {
                        setStyle(line, col, xlstStyleH);
                        setStyle(line + 1, col, xlstStyleH);
                        setStyle(line + 2, col, xlstStyleH);

                    }

                    for (int col = 1; col < 13; col++)
                    {
                        setStyle(line, col, xlstStyleH);
                        setStyle(line + 1, col, xlstStyleH);
                        setStyle(line + 2, col, xlstStyleH);
                    }

                    if (ds != null)
                    {
                        int count = 0;
                        DataTable dt = ds.Tables[0];
                        if (dt.Rows.Count > 0)
                        {
                            setVal(line - 1, 0, viewNumber + ".");
                            strSum += viewNumber + " + ";

                            viewNumber++;

                            foreach (DataRow row in dt.Rows)
                            {
                                if (count >= 1)
                                {
                                    xlsSheet.Rows.Insert(rWater + 1 + j);
                                    xlsSheetEn.Rows.Insert(rWater + 1 + j);
                                    j++;
                                }
                                count++;
                                int tmp = rWater + j;

                                string DateFrom = Func.ParseString(row["DateFrom"]);
                                string DateTo = Func.ParseString(row["DateTo"]);

                                string FromIndex = Func.ParseString(row["FromIndex"]);
                                string ToIndex = Func.ParseString(row["ToIndex"]);
                                string OtherFee01 = Func.ParseString(row["OtherFee01"]);
                                string OtherFee02 = Func.ParseString(row["OtherFee02"]);
                                string Mount = Func.ParseString(row["Mount"]);
                                string vat = Func.ParseString(row["vat"]);
                                if (rWaterVat)
                                {
                                    setValReplace(line, 9, "(%VAT)", "(" + vat.Replace(",00", "") + "%VAT)");
                                    rWaterVat = false;
                                }
                                setVal(tmp, 1, DateFrom);
                                setVal(tmp, 2, DateTo);
                                setVal(tmp, 3, FromIndex);
                                setVal(tmp, 4, ToIndex);
                                setVal(tmp, 5, Mount);
                                setVal(tmp, 6, row["PriceVND"]);

                                setVal(tmp, 8, row["OtherFee01"]);
                                setVal(tmp, 7, row["Sum"]);

                                setVal(tmp, 9, row["SumVAT"]);
                                setVal(tmp, 10, row["OtherFee02"]);
                                setVal(tmp, 11, row["WaterPricePercent"]);
                                setVal(tmp, 12, row["LastPriceVND"]);
                                for (int col = 1; col <= 13; col++)
                                {
                                    setStyle(tmp, col, xlstStyle);
                                }

                                setStyle(tmp, 3, xlstStyleC2);
                                setStyle(tmp, 4, xlstStyleC2);
                                setStyle(tmp, 5, xlstStyleC2);
                                setStyle(tmp, 6, xlstStyle0);
                                setStyle(tmp, 7, xlstStyle0);
                                setStyle(tmp, 8, xlstStyle0);
                                setStyle(tmp, 9, xlstStyle0);
                                setStyle(tmp, 10, xlstStyle2);
                                setStyle(tmp, 11, xlstStyle2);
                                setStyle(tmp, 12, xlstStyle0);

                                mergeCell(tmp, tmp, 12, 13);
                            }

                            DataSet dsSum = new DataSet();
                            //Nuoc
                            //Xuất ra toàn bộ nội dung theo Trang
                            string sqlSum = " SELECT IsNull(A.LastPriceUSD,0) LastPriceUSD      ,IsNull(A.LastPriceVND,0) LastPriceVND  ";
                            sqlSum += " FROM   PaymentElecWater AS A ";
                            sqlSum += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfWaterId > 0  and A.YearMonth in (" + lsYearmonth + ")  and A.DetailType = 2";
                            using (SqlCommand cmSum = db.CreateCommand(sqlSum))
                            {
                                SqlDataAdapter daSum = new SqlDataAdapter(cmSum);
                                daSum.Fill(dsSum);
                                if (daSum != null)
                                {
                                    DataTable dtSum = dsSum.Tables[0];
                                    if (dtSum.Rows.Count > 0)
                                    {
                                        foreach (DataRow row in dtSum.Rows)
                                        {
                                            LastSumPriceVND[5] += Convert.ToDecimal(row["LastPriceVND"]);
                                        }
                                    }
                                }
                            }
                            setVal(rWater + 1 + j, 12, Decimal.Round(LastSumPriceVND[5], 0));
                            mergeCell(rWater + 1 + j, rWater + 1 + j, 1, 11);
                            mergeCell(rWater + 1 + j, rWater + 1 + j, 12, 13);

                            setStyle(rWater + 1 + j, 12, xlstStyleSum0);
                            sumRow += dt.Rows.Count - 1;
                        }
                        else
                        {
                            setVal(line - 1, 0, viewNumber + ".");
                            strSum += viewNumber + " + ";

                            viewNumber++;
                            for (int rHideLine = 0; rHideLine < 6; rHideLine++)
                            {
                                //setHideRow(rHideLine + line - 1);
                            }
                        }
                    }
                }

                //Service
                ds = new DataSet();

                sql = string.Empty;
                sql = " SELECT Service,dbo.fnDateTime(ServiceDateFrom) ServiceDateFrom,dbo.fnDateTime(ServiceDateTo) ServiceDateTo,PriceVND,PriceUSD,VatUSD,VatVND,Mount,Unit,SumVND,SumUSD,isnull(LastPriceVND,0) LastPriceVND,isnull(LastPriceUSD,0) LastPriceUSD";
                sql += " FROM   PaymentService";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth in (" + lsYearmonth + ")";
                sql += " Order By ServiceDate ";

                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    line = rService - 3 + j;
                    removeRow.Add(line + 2);

                    //Phi khác
                    mergeCell(line, line + 1, 1, 1);
                    mergeCell(line, line + 1, 2, 2);
                    mergeCell(line, line + 1, 3, 3);
                    mergeCell(line, line + 1, 4, 4);

                    for (int col = 1; col < 13; col++)
                    {
                        setStyle(line, col, xlstStyleH);
                        setStyle(line + 1, col, xlstStyleH);
                        setStyle(line + 2, col, xlstStyleH);
                    }
                    mergeCell(line, line, 12, 13);
                    mergeCell(line + 1, line + 1, 12, 13);

                    if (ds != null)
                    {
                        int count = 0;
                        DataTable dt = ds.Tables[0];

                        if (dt.Rows.Count > 0)
                        {
                            setVal(line - 1, 0, viewNumber + ".");
                            strSum += viewNumber + " + ";

                            viewNumber++;

                            foreach (DataRow row in dt.Rows)
                            {
                                if (count >= 1)
                                {
                                    xlsSheet.Rows.Insert(rService + 1 + j);
                                    xlsSheetEn.Rows.Insert(rService + 1 + j);
                                    j++;
                                }
                                count++;
                                int tmp = rService + j;

                                string Service = Func.ParseString(row["Service"]);
                                string ServiceDateFrom = Func.ParseString(row["ServiceDateFrom"]);
                                string ServiceDateTo = Func.ParseString(row["ServiceDateTo"]);

                                string Mount = Func.ParseString(row["Mount"]);

                                setVal(tmp, 1, Service);
                                setVal(tmp, 2, Func.ParseString(row["Unit"]));
                                setVal(tmp, 3, ServiceDateFrom);
                                setVal(tmp, 4, ServiceDateTo);
                                setVal(tmp, 5, Mount);

                                setVal(tmp, 6, row["PriceVND"]);
                                setVal(tmp, 8, row["SumVND"]);
                                setVal(tmp, 10, row["VatVND"]);
                                setVal(tmp, 12, row["LastPriceVND"]);

                                mergeCell(tmp, tmp, 6, 7);
                                mergeCell(tmp, tmp, 8, 9);
                                mergeCell(tmp, tmp, 10, 11);
                                mergeCell(tmp, tmp, 12, 13);

                                for (int col = 1; col <= 13; col++)
                                {
                                    setStyle(tmp, col, xlstStyle);
                                }

                                setStyle(tmp, 5, xlstStyleC2);
                                setStyle(tmp, 6, xlstStyle0);
                                setStyle(tmp, 8, xlstStyle0);
                                setStyle(tmp, 10, xlstStyle0);
                                setStyle(tmp, 12, xlstStyle0);

                                LastSumPriceVND[6] += Convert.ToDecimal(row["LastPriceVND"]);
                            }
                            setVal(rService + 1 + j, 12, LastSumPriceVND[6]);

                            setStyle(rService + 1 + j, 12, xlstStyleSum0);
                            mergeCell(rService + 1 + j, rService + 1 + j, 1, 11);
                            mergeCell(rService + 1 + j, rService + 1 + j, 12, 13);

                            sumRow += dt.Rows.Count - 1;
                        }
                        else
                        {
                            setVal(line - 1, 0, viewNumber + ".");
                            strSum += viewNumber + " + ";

                            viewNumber++;
                            for (int rHideLine = 0; rHideLine < 6; rHideLine++)
                            {
                                //setHideRow(rHideLine + line - 1);
                            }
                        }
                    }
                }

                //Paid
                sql = "Select  PaymentType,isnull(MoneyUSD,0) MoneyUSD,isnull(MoneyVND,0) MoneyVND,isnull(PaidUSD,0) PaidUSD,isnull(PaidVND,0) PaidVND,isnull(ExchangeType,0) ExchangeType,isnull(UsdExchange,0) UsdExchange,isnull(YearMonth,0) YearMonth";
                sql += " From    PaymentBillDetail";
                sql += " Where   BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth in (" + lsYearmonth + ") and YearMonth <= " + maxYearMonth + "";
                sql += " and isnull(PaidVND,0) > 0";
                string strYearMonth = "";
                int lineTmp = rPaid - 2 + j;
                removeRow.Add(lineTmp + 1);

                /////En
                mergeCell(lineTmp, lineTmp + 1, 1, 1);
                mergeCell(lineTmp, lineTmp, 2, 3);
                mergeCell(lineTmp, lineTmp, 4, 5);
                mergeCell(lineTmp, lineTmp, 6, 7);
                mergeCell(lineTmp, lineTmp, 8, 9);
                mergeCell(lineTmp, lineTmp, 12, 13);
                /////En
                Hashtable rowNo = new Hashtable();
                decimal[] PaidSumVND = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 };
                decimal[] PaidSumUSD = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 };

                int iPaidNo = 0;
                DataTable dtPaid = DbHelper.GetDataTable(sql);
                if (dtPaid.Rows.Count > 0)
                {
                    setVal(lineTmp - 1, 0, viewNumber + ".");
                    iPaidNo = viewNumber;
                    viewNumber++;

                    for (int i = 0; i < dtPaid.Rows.Count; i++)
                    {
                        string PaymentType = Func.ParseString(dtPaid.Rows[i]["PaymentType"]);
                        string MoneyVND = Func.ParseString(dtPaid.Rows[i]["MoneyVND"]);
                        string PaidVND = Func.ParseString(dtPaid.Rows[i]["PaidVND"]);
                        string ExchangeType = Func.ParseString(dtPaid.Rows[i]["ExchangeType"]);
                        string UsdExchange = Func.ParseString(dtPaid.Rows[i]["UsdExchange"]);
                        string YearMonth = Func.ParseString(dtPaid.Rows[i]["YearMonth"]);

                        if (!rowNo.Contains(YearMonth))
                        {
                            if (rowNo.Count != 0)
                            {
                                xlsSheet.Rows.Insert(rPaid + j + 1);
                                xlsSheetEn.Rows.Insert(rPaid + j + 1);
                                j++;
                            }
                            rowNo.Add(YearMonth, j);
                        }
                        int m = Func.ParseInt(rowNo[YearMonth]);
                        strYearMonth = YearMonth;
                        decimal tmpVND = Convert.ToDecimal(MoneyVND) - Convert.ToDecimal(PaidVND);
                        PaidPriceVND += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]);

                        setVal(rPaid + m, 1, YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4));
                        switch (PaymentType)
                        {
                            case "1":
                                //Rent
                                setVal(rPaid + m, 2, dtPaid.Rows[i]["PaidVND"]);
                                PaidSumVND[0] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]);

                                break;
                            case "2":
                                //Manager
                                setVal(rPaid + m, 4, dtPaid.Rows[i]["PaidVND"]);
                                PaidSumVND[1] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]);

                                break;
                            case "3":
                                //Parking
                                setVal(rPaid + m, 6, dtPaid.Rows[i]["PaidVND"]);
                                PaidSumVND[2] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]);
                                break;
                            case "4":
                                //Extra
                                setVal(rPaid + m, 8, dtPaid.Rows[i]["PaidVND"]);
                                PaidSumVND[3] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]);
                                break;
                            case "5":
                                setVal(rPaid + m, 10, dtPaid.Rows[i]["PaidVND"]);
                                PaidSumVND[4] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]);
                                break;
                            case "6":
                                setVal(rPaid + m, 11, dtPaid.Rows[i]["PaidVND"]);
                                PaidSumVND[5] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]);
                                break;
                            case "7":
                                setVal(rPaid + m, 12, dtPaid.Rows[i]["PaidVND"]);
                                PaidSumVND[6] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]);
                                break;
                            default:
                                break;
                        }
                        /////////////////////////////////////////////////
                        for (int col = 1; col <= 13; col++)
                        {
                            setStyle(rPaid + m, col, xlstStyle);
                        }

                        //Rent
                        setStyle(rPaid + m, 2, xlstStyle0);
                        setStyle(rPaid + m, 3, xlstStyle0);

                        //Manager
                        setStyle(rPaid + m, 4, xlstStyle0);
                        setStyle(rPaid + m, 5, xlstStyle0);

                        //Parking
                        setStyle(rPaid + m, 6, xlstStyle0);
                        setStyle(rPaid + m, 7, xlstStyle0);

                        //Extra
                        setStyle(rPaid + m, 8, xlstStyle0);
                        setStyle(rPaid + m, 9, xlstStyle0);

                        setStyle(rPaid + m, 10, xlstStyle0);

                        setStyle(rPaid + m, 11, xlstStyle0);

                        setStyle(rPaid + m, 12, xlstStyle0);
                        setStyle(rPaid + m, 13, xlstStyle0);

                        mergeCell(rPaid + m, rPaid + m, 2, 3);
                        mergeCell(rPaid + m, rPaid + m, 4, 5);
                        mergeCell(rPaid + m, rPaid + m, 6, 7);
                        mergeCell(rPaid + m, rPaid + m, 8, 9);
                        mergeCell(rPaid + m, rPaid + m, 12, 13);
                    }
                }
                else
                {
                    setVal(lineTmp - 1, 0, viewNumber + ".");
                    iPaidNo = viewNumber;
                    viewNumber++;

                    for (int rHideLine = 0; rHideLine < 6; rHideLine++)
                    {
                        //setHideRow(rHideLine + lineTmp - 1);
                    }
                }

                lineTmp = rPaid - 2 + j;

                setVal(lineTmp + 3, 2, PaidSumVND[0]);
                setVal(lineTmp + 3, 4, PaidSumVND[1]);
                setVal(lineTmp + 3, 6, PaidSumVND[2]);
                setVal(lineTmp + 3, 8, PaidSumVND[3]);
                setVal(lineTmp + 3, 10, PaidSumVND[4]);
                setVal(lineTmp + 3, 11, PaidSumVND[5]);
                setVal(lineTmp + 3, 12, PaidSumVND[6]);

                mergeCell(lineTmp + 3, lineTmp + 3, 2, 3);
                mergeCell(lineTmp + 3, lineTmp + 3, 4, 5);
                mergeCell(lineTmp + 3, lineTmp + 3, 6, 7);
                mergeCell(lineTmp + 3, lineTmp + 3, 8, 9);
                mergeCell(lineTmp + 3, lineTmp + 3, 12, 13);

                ///////////////
                setStyle(lineTmp + 3, 2, xlstStyleSum1);
                setStyle(lineTmp + 3, 3, xlstStyleSum0);
                setStyle(lineTmp + 3, 4, xlstStyleSum0);
                setStyle(lineTmp + 3, 5, xlstStyleSum0);
                setStyle(lineTmp + 3, 6, xlstStyleSum0);
                setStyle(lineTmp + 3, 7, xlstStyleSum0);
                setStyle(lineTmp + 3, 8, xlstStyleSum0);
                setStyle(lineTmp + 3, 9, xlstStyleSum0);
                setStyle(lineTmp + 3, 10, xlstStyleSum0);
                setStyle(lineTmp + 3, 11, xlstStyleSum0);
                setStyle(lineTmp + 3, 12, xlstStyleSum0);
                setStyle(lineTmp + 3, 13, xlstStyleSum0);

                ///////////////DEPT
                sql = "  Select *";
                sql += " From   v_DeptBill";
                sql += " Where  BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth not in (" + lsYearmonth + ") and YearMonth < " + maxYearMonth + "";
                sql += " And    (DeptUsd <> 0 or DeptVnd <> 0)";
                strYearMonth = "";
                lineTmp = rDept - 2 + j;
                removeRow.Add(lineTmp + 1);

                //////En
                mergeCell(lineTmp, lineTmp + 1, 1, 1);
                mergeCell(lineTmp, lineTmp, 2, 3);
                mergeCell(lineTmp, lineTmp, 4, 5);
                mergeCell(lineTmp, lineTmp, 6, 7);
                mergeCell(lineTmp, lineTmp, 8, 9);
                mergeCell(lineTmp, lineTmp, 12, 13);
                //////En
                rowNo = new Hashtable();
                decimal DeptPriceVND = 0;
                decimal DeptPriceUSD = 0;

                decimal[] DeptSumVND = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 };
                decimal[] DeptSumUSD = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 };

                DataTable dtDept = DbHelper.GetDataTable(sql);
                if (dtDept.Rows.Count > 0)
                {
                    setVal(lineTmp - 1, 0, viewNumber + ".");

                    strSum += viewNumber + " + ";

                    viewNumber++;

                    for (int i = 0; i < dtDept.Rows.Count; i++)
                    {
                        string PaymentType = Func.ParseString(dtDept.Rows[i]["PaymentType"]);
                        string DeptVND = Func.ParseString(dtDept.Rows[i]["DeptVND"]);
                        string YearMonth = Func.ParseString(dtDept.Rows[i]["YearMonth"]);

                        if (!rowNo.Contains(YearMonth))
                        {
                            if (rowNo.Count != 0)
                            {
                                xlsSheet.Rows.Insert(rDept + j + 1);
                                xlsSheetEn.Rows.Insert(rDept + j + 1);
                                j++;
                            }
                            rowNo.Add(YearMonth, j);
                        }
                        int m = Func.ParseInt(rowNo[YearMonth]);
                        strYearMonth = YearMonth;

                        DeptPriceVND += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);

                        setVal(rDept + m, 1, YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4));

                        switch (PaymentType)
                        {
                            case "1":
                                //Rent
                                setVal(rDept + m, 3, dtDept.Rows[i]["DeptVND"]);
                                DeptSumVND[0] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);

                                break;
                            case "2":
                                //Manager
                                setVal(rDept + m, 5, dtDept.Rows[i]["DeptVND"]);
                                DeptSumVND[1] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);

                                break;
                            case "3":
                                //Parking
                                setVal(rDept + m, 7, dtDept.Rows[i]["DeptVND"]);
                                DeptSumVND[2] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);
                                break;
                            case "4":
                                //Extra
                                setVal(rDept + m, 9, dtDept.Rows[i]["DeptVND"]);
                                DeptSumVND[3] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);
                                break;
                            case "5":
                                setVal(rDept + m, 10, dtDept.Rows[i]["DeptVND"]);
                                DeptSumVND[4] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);
                                break;
                            case "6":
                                setVal(rDept + m, 11, dtDept.Rows[i]["DeptVND"]);
                                DeptSumVND[5] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);
                                break;
                            case "7":
                                setVal(rDept + m, 13, dtDept.Rows[i]["DeptVND"]);
                                DeptSumVND[6] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);
                                break;
                            default:
                                break;
                        }
                        for (int col = 1; col <= 13; col++)
                        {
                            setStyle(rDept + m, col, xlstStyle);
                        }
                        setStyle(rDept + m, 2, xlstStyle1);
                        setStyle(rDept + m, 3, xlstStyle0);

                        //Manager
                        setStyle(rDept + m, 4, xlstStyle1);
                        setStyle(rDept + m, 5, xlstStyle0);

                        //Parking
                        setStyle(rDept + m, 6, xlstStyle1);
                        setStyle(rDept + m, 7, xlstStyle0);

                        //Extra
                        setStyle(rDept + m, 8, xlstStyle1);
                        setStyle(rDept + m, 9, xlstStyle0);

                        setStyle(rDept + m, 10, xlstStyle0);

                        setStyle(rDept + m, 11, xlstStyle0);

                        setStyle(rDept + m, 12, xlstStyle1);
                        setStyle(rDept + m, 13, xlstStyle0);

                        mergeCell(rDept + m, rDept + m, 2, 3);
                        mergeCell(rDept + m, rDept + m, 4, 5);
                        mergeCell(rDept + m, rDept + m, 6, 7);
                        mergeCell(rDept + m, rDept + m, 8, 9);
                        mergeCell(rDept + m, rDept + m, 10, 11);
                        mergeCell(rDept + m, rDept + m, 12, 13);
                    }
                }
                else
                {
                    setVal(lineTmp - 1, 0, viewNumber + ".");

                    strSum += viewNumber + " + ";

                    viewNumber++;

                    for (int rHideLine = 0; rHideLine < 5; rHideLine++)
                    {
                        //setHideRow(rHideLine + lineTmp - 1);
                    }
                }
                lineTmp = rDept - 2 + j;

                setVal(lineTmp + 3, 3, DeptSumVND[0]);
                setVal(lineTmp + 3, 5, DeptSumVND[1]);
                setVal(lineTmp + 3, 7, DeptSumVND[2]);
                setVal(lineTmp + 3, 9, DeptSumVND[3]);
                setVal(lineTmp + 3, 10, DeptSumVND[4]);
                setVal(lineTmp + 3, 11, DeptSumVND[5]);
                setVal(lineTmp + 3, 13, DeptSumVND[6]);

                setStyle(lineTmp + 3, 2, xlstStyleSum1);
                setStyle(lineTmp + 3, 3, xlstStyleSum0);
                setStyle(lineTmp + 3, 4, xlstStyleSum0);
                setStyle(lineTmp + 3, 5, xlstStyleSum0);
                setStyle(lineTmp + 3, 6, xlstStyleSum0);
                setStyle(lineTmp + 3, 7, xlstStyleSum0);
                setStyle(lineTmp + 3, 8, xlstStyleSum0);
                setStyle(lineTmp + 3, 9, xlstStyleSum0);
                setStyle(lineTmp + 3, 10, xlstStyleSum0);
                setStyle(lineTmp + 3, 11, xlstStyleSum0);
                setStyle(lineTmp + 3, 12, xlstStyleSum0);
                setStyle(lineTmp + 3, 13, xlstStyleSum0);

                mergeCell(lineTmp + 3, lineTmp + 3, 2, 3);
                mergeCell(lineTmp + 3, lineTmp + 3, 4, 5);
                mergeCell(lineTmp + 3, lineTmp + 3, 6, 7);
                mergeCell(lineTmp + 3, lineTmp + 3, 8, 9);
                mergeCell(lineTmp + 3, lineTmp + 3, 10, 11);
                mergeCell(lineTmp + 3, lineTmp + 3, 12, 13);

                strSum = strSum.Substring(0, strSum.Length - 2) + (iPaidNo > 0 ? " - " + iPaidNo : "") + ":";

                decimal AllSumVND = 0;
                decimal AllSumUSD = 0;
                for (int i = 0; i < 7; i++)
                {
                    AllSumVND += LastSumPriceVND[i];
                    AllSumUSD += LastSumPriceUSD[i];
                }

                AllSumVND -= PaidPriceVND;
                AllSumUSD -= PaidPriceUSD;

                AllSumVND += DeptPriceVND;
                AllSumUSD += DeptPriceUSD;

                //setVal(rSumVND + j, cSumVND - 2, Func.FormatNumber_New(AllSumUSD));
                setVal(rSumVND + j, cSumVND, Func.FormatNumber_New(Math.Truncate(Convert.ToDecimal(AllSumVND))).Replace(",00", ""));

                mergeCell(rSumVND + j, rSumVND + j, 10, 13);

                //format
                //setStyle(rSumVND + j, cSumVND - 2, xlstStyleCH);
                setStyle(rSumVND + j, cSumVND, xlstStyleCH);

                //AllSumVND += Convert.ToDecimal(AllSumUSD * Convert.ToDecimal(txtUsdExchange.Text));

                string strMoney = Func.docso(Convert.ToDecimal(AllSumVND));
                string strMoneyEn = Func.DocSo_En(Convert.ToDecimal(AllSumVND));
                //Hop Dong
                setValReplace(rContract, cContract, "{%HOP_DONG%}", String.IsNullOrEmpty(contract) ? "" : contract.Substring(1));

                //Sum 1 + 2...
                setVal(rSum + j - 1, 7, strSum);
                //Sum số tiền
                setVal(rSum + j - 1, 10, Func.FormatNumber_New(Math.Truncate(Convert.ToDecimal(AllSumVND))).Replace(",00", ""));
                mergeCell(rSum + j - 1, rSum + j - 1, 10, 13);
                setStyle(rSum + j - 1, 10, xlstStyleCSum0);

                //Chữ
                //mergeCell(rSumRead + j, rSumRead + j, 7, 13);
                setVal(rSum + j + 1, 7, strMoney.ToUpper());
                xlsSheetEn[rSum + j + 1, 7].Value = strMoneyEn.ToUpper();

                setStyle(rSum + j + 1, 7, xlstStyleLeftCH);

                removeRow.Sort();
                removeRow.Reverse();
                for (int r = 0; r < removeRow.Count; r++)
                {
                    setHideRow(Func.ParseInt(removeRow[r]));
                }

                xlbBook.Save(fileNameDes);
                ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true);
            }
        }
Exemplo n.º 50
0
        protected void btnExport_Click(object sender, EventArgs e)
        {
            C1XLBook xlbBook = new C1XLBook();
            XLStyle xlstStyle = new XLStyle(xlbBook);
            xlstStyle.AlignHorz = XLAlignHorzEnum.Left;
            xlstStyle.WordWrap = true;
            xlstStyle.Font = new Font("", 8, FontStyle.Regular);
            xlstStyle.SetBorderColor(Color.Black);
            xlstStyle.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyle.BorderTop = XLLineStyleEnum.Thin;
            xlstStyle.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyle.BorderRight = XLLineStyleEnum.Thin;
            //xlstStyle.Format = "#,##0.00_);(#,##0.00)";
            xlstStyle.AlignVert = XLAlignVertEnum.Top;

            XLStyle xlstStyleN = new XLStyle(xlbBook);
            xlstStyleN.AlignHorz = XLAlignHorzEnum.Right;
            xlstStyleN.WordWrap = true;
            xlstStyleN.Font = new Font("", 8, FontStyle.Regular);
            xlstStyleN.SetBorderColor(Color.Black);
            xlstStyleN.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyleN.BorderTop = XLLineStyleEnum.Thin;
            xlstStyleN.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyleN.BorderRight = XLLineStyleEnum.Thin;
            xlstStyleN.Format = "#,##0.00_);(#,##0.00)";
            xlstStyleN.AlignVert = XLAlignVertEnum.Top;

            XLStyle xlstStyleS = new XLStyle(xlbBook);
            xlstStyleS.AlignHorz = XLAlignHorzEnum.Left;
            xlstStyleS.WordWrap = true;
            xlstStyleS.Font = new Font("", 8, FontStyle.Bold);
            xlstStyleS.SetBorderColor(Color.Black);
            xlstStyleS.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyleS.BorderTop = XLLineStyleEnum.Thin;
            xlstStyleS.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyleS.BorderRight = XLLineStyleEnum.Thin;
            xlstStyleS.Format = "#,##0.00_);(#,##0.00)";
            xlstStyleS.AlignVert = XLAlignVertEnum.Top;

            string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\MayMocThietBi.xls");
            if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\MayMocThietBi"))
            {
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\MayMocThietBi"));
            }

            string strDT = DateTime.Now.ToString("yyyyMMddHHmmss");
            string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\MayMocThietBi\MayMocThietBi" + strDT + ".xls";
            string strFilePathExport = "Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/MayMocThietBi/MayMocThietBi" + strDT + ".xls";

            string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath);

            File.Copy(fileName, fileNameDes);

            xlbBook.Load(fileNameDes);

            DataSet ds = new DataSet();
            string sql = string.Empty;

            //sql = " SELECT *";
            //sql += " FROM Report_BuildingInfo where delflag = '0'";
            ////sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' ";
            ////sql += " AND ((NgayKetThuc is null) OR ";
            ////sql += "      (NgayKetThuc is not null and substring(NgayKetThuc,1,6) >= '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'))";

            //using (SqlDatabase db = new SqlDatabase())
            //{
            //    using (SqlCommand cm = db.CreateCommand(sql))
            //    {
            //        SqlDataAdapter da = new SqlDataAdapter(cm);
            //        da.Fill(ds);
            //        if (ds != null)
            //        {
            //            XLSheet xlsSheetMenu = xlbBook.Sheets["Menu"];
            //            xlsSheetMenu[2, 1].Value = xlsSheetMenu[2, 1].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue);

            //            DataTable dt = ds.Tables[0];
            //            foreach (DataRow rowType in dt.Rows)
            //            {
            //                int stt = 0;
            //                string id = rowType["id"].ToString();
            //                string sheet = rowType["Sheet"].ToString();
            //                int NumOfCol = Func.ParseInt(rowType["NoOfColumn"].ToString());
            //                string SqlSelect = rowType["SqlSelect"].ToString().Replace("{%NAM_THANG%}", drpYear.SelectedValue + drpMonth.SelectedValue);
            //                SqlSelect = SqlSelect.Replace("{%TOA_NHA%}", Func.ParseString(Session["__BUILDINGID__"]));
            //                int CellY = Func.ParseInt(rowType["CellBeginY"].ToString());
            //                int CellX = Func.ParseInt(rowType["CellBeginX"].ToString());
            //                string[] Col = rowType["SumCol"].ToString().Split(',');

            //                decimal[] SumCol = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            //                using (SqlCommand cmSheet = db.CreateCommand(SqlSelect))
            //                {
            //                    DataSet dsSheet = new DataSet();
            //                    SqlDataAdapter daSheet = new SqlDataAdapter(cmSheet);
            //                    daSheet.Fill(dsSheet);
            //                    if (dsSheet != null)
            //                    {
            //                        XLSheet xlsSheet = xlbBook.Sheets[sheet];

            //                        DataTable dtSheet = dsSheet.Tables[0];
            //                        foreach (DataRow rowSheet in dtSheet.Rows)
            //                        {
            //                            xlsSheet[CellY + stt, CellX].Style = xlstStyle;
            //                            xlsSheet[CellY + stt, CellX].Value = Func.ParseString(++stt);

            //                            for (int k = 0; k < NumOfCol; k++)
            //                            {
            //                                string tmp = rowSheet[k].ToString();

            //                                xlsSheet[CellY + stt - 1, CellX + k + 1].Value = rowSheet[k];
            //                                xlsSheet[CellY + stt - 1, CellX + k + 1].Style = xlstStyle;

            //                                switch (rowSheet[k].GetType().Name)
            //                                {
            //                                    case "Decimal":
            //                                        //xlsSheet[CellY + stt - 1, CellX + k + 1].Value = Func.ParseDouble(tmp);
            //                                        //break;
            //                                        SumCol[k] += Convert.ToDecimal(rowSheet[k]);
            //                                        xlsSheet[CellY + stt - 1, CellX + k + 1].Style = xlstStyleN;

            //                                        break;
            //                                    case "Double":
            //                                        //xlsSheet[CellY + stt - 1, CellX + k + 1].Value = Func.ParseDouble(tmp);
            //                                        SumCol[k] += Convert.ToDecimal(rowSheet[k]);
            //                                        xlsSheet[CellY + stt - 1, CellX + k + 1].Style = xlstStyleN;

            //                                        break;
            //                                    //break;
            //                                    case "Int32":
            //                                        //xlsSheet[CellY + stt - 1, CellX + k + 1].Value = Func.ParseInt(tmp);
            //                                        SumCol[k] += Convert.ToDecimal(rowSheet[k]);
            //                                        xlsSheet[CellY + stt - 1, CellX + k + 1].Style = xlstStyleN;

            //                                        break;
            //                                    //break;
            //                                    case "Single":
            //                                        SumCol[k] += Convert.ToDecimal(rowSheet[k]);
            //                                        xlsSheet[CellY + stt - 1, CellX + k + 1].Style = xlstStyleN;

            //                                        break;

            //                                    //xlsSheet[CellY + stt - 1, CellX + k + 1].Value = rowSheet[k];// Func.ParseInt(tmp);
            //                                    //xlsSheet[CellY + stt - 1, CellX + k + 1].Style = xlstStyleN;
            //                                    default:
            //                                        xlsSheet[CellY + stt - 1, CellX + k + 1].Value = tmp;
            //                                        xlsSheet[CellY + stt - 1, CellX + k + 1].Style = xlstStyle;
            //                                        break;
            //                                }
            //                                //xlsSheet[CellY + stt - 1, CellX + k + 1].Value = tmp;
            //                                //xlsSheet[CellY + stt - 1, CellX + k + 1].Style = xlstStyle;
            //                            }
            //                        }
            //                        if (!String.IsNullOrEmpty(Col[0]))
            //                        {
            //                            for (int m = 0; m < NumOfCol + 1; m++)
            //                            {
            //                                xlsSheet[CellY + stt, m].Style = xlstStyleS;
            //                            }
            //                        }
            //                        if (!String.IsNullOrEmpty(Col[0]))
            //                        {
            //                            xlsSheet[CellY + stt, 0].Value = "Tổng cộng";
            //                            XLCellRange mrCell = new XLCellRange(CellY + stt, CellY + stt, 0, Func.ParseInt(Col[0]));
            //                            xlsSheet.MergedCells.Add(mrCell);
            //                            for (int m = 0; m <= Func.ParseInt(Col[0]); m++)
            //                            {
            //                                xlsSheet[CellY + stt, m].Style = xlstStyleS;
            //                            }
            //                        }
            //                        for (int m = 0; m < Col.Length; m++)
            //                        {
            //                            if (!String.IsNullOrEmpty(Col[m]))
            //                            {
            //                                xlsSheet[CellY + stt, CellX + Func.ParseInt(Col[m]) + 1].Value = SumCol[Func.ParseInt(Col[m])];
            //                                xlsSheet[CellY + stt, CellX + Func.ParseInt(Col[m]) + 1].Style = xlstStyleS;
            //                            }
            //                        }
            //                    }
            //                }
            //            }
            //        }
            //    }
            //}
            ds = new DataSet();
            sql = string.Empty;

            sql = " SELECT *";
            sql += " FROM Report_BuildingInfo where id = 54 and delflag = '2'";

            using (SqlDatabase db = new SqlDatabase())
            {
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    if (ds != null)
                    {
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            int stt = 0;
                            string id = rowType["id"].ToString();
                            string sheet = "BaoCao";
                            int NumOfCol = Func.ParseInt(rowType["NoOfColumn"].ToString());
                            string SqlSelect = rowType["SqlSelect"].ToString().Replace("{%NAM_THANG%}", drpYear.SelectedValue + drpMonth.SelectedValue);
                            SqlSelect = SqlSelect.Replace("{%TOA_NHA%}", Func.ParseString(Session["__BUILDINGID__"]));
                            int CellY = Func.ParseInt(rowType["CellBeginY"].ToString());
                            int CellX = Func.ParseInt(rowType["CellBeginX"].ToString());
                            string[] Col = rowType["SumCol"].ToString().Split(',');

                            decimal[] SumCol = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
                            XLCellRange mrCell = new XLCellRange(0, 0, 0, 0);

                            string group = "";
                            int i = 0;
                            using (SqlCommand cmSheet = db.CreateCommand(SqlSelect))
                            {
                                DataSet dsSheet = new DataSet();
                                SqlDataAdapter daSheet = new SqlDataAdapter(cmSheet);
                                daSheet.Fill(dsSheet);
                                if (dsSheet != null)
                                {
                                    XLSheet xlsSheet = xlbBook.Sheets[sheet];
                                    xlsSheet[0, 0].Value = xlsSheet[0, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue);
                                    xlsSheet[0, 0].Value = xlsSheet[0, 0].Value.ToString().Replace("{%TOA_NHA%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue);

                                    DataTable dtSheet = dsSheet.Tables[0];
                                    foreach (DataRow rowSheet in dtSheet.Rows)
                                    {
                                        string col11 = rowSheet[NumOfCol].ToString();

                                        if (!group.Equals(col11))
                                        {
                                            xlsSheet[CellY + i, CellX].Value = col11;
                                            group = col11;

                                            for (int k = 0; k <= NumOfCol; k++)
                                            {
                                                xlsSheet[CellY + i, CellX + k].Style = xlstStyleS;
                                            }
                                            mrCell = new XLCellRange(CellY + i, CellY + i, 0, NumOfCol);
                                            xlsSheet.MergedCells.Add(mrCell);

                                            xlsSheet[CellY + i, CellX].Style = xlstStyleS;
                                            i++;
                                        }
                                        xlsSheet[CellY + i, CellX + 0].Value = ++stt;
                                        xlsSheet[CellY + i, CellX + 0].Style = xlstStyle;

                                        for (int m = 1; m <= NumOfCol; m++)
                                        {
                                            xlsSheet[CellY + i, CellX + m].Value = rowSheet[m - 1];
                                            xlsSheet[CellY + i, CellX + m].Style = xlstStyle;
                                        }
                                        ++i;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            xlbBook.Save(fileNameDes);
            ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true);
        }
Exemplo n.º 51
0
        protected void btnExport_Click(object sender, EventArgs e)
        {
            string type = Func.ParseString(Request["type"]);

            DataSet ds = new DataSet();
            string sql = string.Empty;

            //sql = " SELECT *";
            //sql += " FROM v_BuildingStatusInfo";
            //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and StatusDate >= '" + Func.FormatYYYYmmdd(txtFromDate.Text.Substring(0, 10)) + "' and StatusDate <= '" + Func.FormatYYYYmmdd(txtToDate.Text.Substring(0, 10)) + "' and Type = '" + type + "'";

            sql = "  SELECT  right('0'+convert(varchar,[Month]),2) + '/' + convert(varchar,[Year]),[Week],MainName,SubName";
            sql += " ,dbo.fnDateTime(ExecDate),ExecCompany,ExecDescription,ExecComment,ExecConfirmer,ModifiedBy,dbo.fnDateTime(Modified)";
            sql += " FROM BD_Maintenance ";
            sql += " WHERE    BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' ";
            sql += " and  convert(varchar,[Year]) + right('0'+convert(varchar,[Month]),2) >= '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'";
            sql += " and  convert(varchar,[Year]) + right('0'+convert(varchar,[Month]),2) <= '" + drpYearTo.SelectedValue + drpMonthTo.SelectedValue + "'";
            sql += " and DelFlag = '0'  ";
            sql += " and UPPER(IsMaintenance) = 'X'  ";
            sql += " Order by  right('0'+convert(varchar,[Month]),2) + '/' + convert(varchar,[Year]), MainName, SubName,Week ";

            using (SqlDatabase db = new SqlDatabase())
            {
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    db.Close();

                    if (ds != null)
                    {
                        C1XLBook xlbBook = new C1XLBook();
                        string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\KeHoachBaoTri.xlsx");
                        if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\KeHoachBaoTri"))
                        {
                            Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\KeHoachBaoTri"));
                        }
                        string strDT = DateTime.Now.ToString("yyyyMMddHHmmss");

                        string strFilePath = "";
                        string strFilePathExport = "";

                        strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\KeHoachBaoTri\KeHoachBaoTri" + strDT + ".xlsx";
                        strFilePathExport = "Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/KeHoachBaoTri/KeHoachBaoTri" + strDT + ".xlsx";

                        string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath);
                        File.Copy(fileName, fileNameDes);

                        xlbBook.Load(fileNameDes);
                        string sheet = "KeHoachBaoTri";

                        XLSheet xlsSheet = xlbBook.Sheets[sheet];

                        int i = 3;
                        XLCellRange mrCell = new XLCellRange(0, 0, 0, 2);
                        xlsSheet.MergedCells.Add(mrCell);

                        XLStyle xlstStyle = new XLStyle(xlbBook);
                        xlstStyle.AlignHorz = XLAlignHorzEnum.Center;
                        xlstStyle.AlignVert = XLAlignVertEnum.Center;
                        xlstStyle.WordWrap = true;
                        xlstStyle.Font = new Font("", 8, FontStyle.Regular);
                        xlstStyle.SetBorderColor(Color.Black);
                        xlstStyle.BorderBottom = XLLineStyleEnum.Thin;
                        xlstStyle.BorderTop = XLLineStyleEnum.Thin;
                        xlstStyle.BorderLeft = XLLineStyleEnum.Thin;
                        xlstStyle.BorderRight = XLLineStyleEnum.Thin;

                        XLStyle xlstStyleB = new XLStyle(xlbBook);
                        xlstStyleB.AlignHorz = XLAlignHorzEnum.Left;
                        xlstStyleB.AlignVert = XLAlignVertEnum.Top;
                        xlstStyleB.WordWrap = false;
                        xlstStyleB.Font = new Font("", 8, FontStyle.Regular);
                        xlstStyleB.SetBorderColor(Color.Black);
                        xlstStyleB.BorderBottom = XLLineStyleEnum.Thin;
                        xlstStyleB.BorderTop = XLLineStyleEnum.Thin;
                        xlstStyleB.BorderLeft = XLLineStyleEnum.Thin;
                        xlstStyleB.BorderRight = XLLineStyleEnum.Thin;

                        xlsSheet[0, 0].Value = xlsSheet[0, 0].Value.ToString().Replace("{%BUILDING%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'"));
                        string tmp = Func.ParseString( xlsSheet[1, 0].Value);
                        tmp = tmp.Replace("{%NAM%}", drpYear.SelectedValue);
                        tmp = tmp.Replace("{%THANG%}", drpMonth.SelectedValue);
                        tmp = tmp.Replace("{%NAM_TO%}", drpYearTo.SelectedValue);
                        tmp = tmp.Replace("{%THANG_TO%}", drpMonthTo.SelectedValue);
                        xlsSheet[1, 0].Value = tmp;

                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            string col01 = rowType[0].ToString();
                            string col02 = rowType[1].ToString();
                            string col03 = rowType[2].ToString();
                            string col04 = rowType[3].ToString();
                            string col05 = rowType[4].ToString();
                            string col06 = rowType[5].ToString();
                            string col07 = rowType[6].ToString();
                            string col08 = rowType[7].ToString();
                            string col09 = rowType[8].ToString();
                            string col10 = rowType[9].ToString();
                            string col11 = rowType[10].ToString();

                            xlsSheet[i, 0].Value = col01;
                            xlsSheet[i, 1].Value = col02;
                            xlsSheet[i, 2].Value = col03;
                            xlsSheet[i, 3].Value = col04;
                            xlsSheet[i, 4].Value = col05;
                            xlsSheet[i, 5].Value = col06;
                            xlsSheet[i, 6].Value = col07;
                            xlsSheet[i, 7].Value = col08;
                            xlsSheet[i, 8].Value = col09;
                            xlsSheet[i, 9].Value = col10;
                            xlsSheet[i, 10].Value = col11;

                            xlsSheet[i, 0].Style = xlstStyle;
                            xlsSheet[i, 1].Style = xlstStyleB;
                            xlsSheet[i, 2].Style = xlstStyleB;
                            xlsSheet[i, 3].Style = xlstStyleB;
                            xlsSheet[i, 4].Style = xlstStyleB;
                            xlsSheet[i, 5].Style = xlstStyleB;
                            xlsSheet[i, 6].Style = xlstStyleB;
                            xlsSheet[i, 7].Style = xlstStyleB;
                            xlsSheet[i, 8].Style = xlstStyleB;
                            xlsSheet[i, 9].Style = xlstStyleB;
                            xlsSheet[i, 10].Style = xlstStyleB;
                            xlsSheet[i, 11].Style = xlstStyleB;
                            ++i;
                        }

                        ////ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('/CSV/DownloadZipFile.aspx'," + PopupWidth + "," + PopupHeight + ",'EditFlat', true);", true);

                        ////xlsSheet[i++, 0].Value = "Ghi chú:";
                        //DataSet ds1 = new DataSet();
                        //sql = string.Empty;

                        //sql = " SELECT *";
                        //sql += " FROM BD_WorkingHour";
                        //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and DelFlag <> 1";
                        //sql += " Order By Name";

                        //using (SqlCommand cm1 = db.CreateCommand(sql))
                        //{
                        //    SqlDataAdapter da1 = new SqlDataAdapter(cm1);
                        //    da1.Fill(ds1);
                        //    db.Close();

                        //    if (ds != null)
                        //    {

                        //        xlsSheet[i++ + 1, 0].Value = "Ghi chú:";
                        //        DataTable dt1 = ds1.Tables[0];
                        //        foreach (DataRow rowType in dt1.Rows)
                        //        {
                        //            i++;
                        //            string Ma = rowType["WorkingHourId"].ToString();
                        //            string Name = rowType["Name"].ToString();
                        //            xlsSheet[i, 0].Value = Ma + ":";
                        //            xlsSheet[i, 1].Value = Name;
                        //        }
                        //        xlsSheet[i + 1, 0].Value = "OF:";
                        //        xlsSheet[i + 1, 1].Value = "OF: nghỉ";
                        //    }
                        //}
                        //string dataPath = HttpContext.Current.Server.MapPath(@"\Building\Staff\DataTmp");
                        //string tmpFolder = dataPath;
                        //if (!Directory.Exists(tmpFolder))
                        //{
                        //    Directory.CreateDirectory(tmpFolder);
                        //}
                        //string name = "KhaiBaoLichLamViec_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls";
                        //string fileName = Path.Combine(tmpFolder, name);
                        //                        string fileNameDes = HttpContext.Current.Server.MapPath(@"\Report\Template\THSLXT_tpl_1.xlsx");

                        xlbBook.Save(fileNameDes);
                        //Session["ZipFilePath"] = null;
                        //Session["ZipFilePath"] = fileName;

                        ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true);

                    }
                }
            }
        }
Exemplo n.º 52
0
        protected void btnExport_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            string sql = string.Empty;

            sql = " SELECT *";
            sql += " FROM v_TicketStubs";
            sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' ";
            sql += " AND (ReceiveDate is not null and substring(ReceiveDate,1,6) >= '" + drpYear.SelectedValue + drpMonth.SelectedValue + "')";

            using (SqlDatabase db = new SqlDatabase())
            {
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    db.Close();

                    if (ds != null)
                    {
                        C1XLBook xlbBook = new C1XLBook();
                        string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\ThongTinVeXeLuot.xls");
                        if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\ThongTinVeXeLuot"))
                        {
                            Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\ThongTinVeXeLuot"));
                        }

                        string strDT = DateTime.Now.ToString("yyyyMMddHHmmss");
                        string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\ThongTinVeXeLuot\ThongTinVeXeLuot" + strDT + ".xls";
                        string strFilePathExport = "Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/ThongTinVeXeLuot/ThongTinVeXeLuot" + strDT + ".xls";

                        string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath);

                        File.Copy(fileName, fileNameDes);

                        xlbBook.Load(fileNameDes);
                        XLSheet xlsSheet = xlbBook.Sheets["BaoCao"];

                        int i = 3;
                        XLCellRange mrCell = new XLCellRange(0, 0, 0, 2);
                        xlsSheet.MergedCells.Add(mrCell);

                        XLStyle xlstStyle = new XLStyle(xlbBook);
                        //xlstStyle.AlignHorz = XLAlignHorzEnum.Left;
                        xlstStyle.AlignVert = XLAlignVertEnum.Top;
                        xlstStyle.WordWrap = true;
                        xlstStyle.Font = new Font("", 8, FontStyle.Regular);
                        xlstStyle.SetBorderColor(Color.Black);
                        xlstStyle.BorderBottom = XLLineStyleEnum.Thin;
                        xlstStyle.BorderTop = XLLineStyleEnum.Thin;
                        xlstStyle.BorderLeft = XLLineStyleEnum.Thin;
                        xlstStyle.BorderRight = XLLineStyleEnum.Thin;
                        xlstStyle.Format = "#,##0.00_);(#,##0.00)";

                        XLStyle xlstStyle01 = new XLStyle(xlbBook);
                        xlstStyle01.AlignHorz = XLAlignHorzEnum.Center;
                        xlstStyle01.AlignVert = XLAlignVertEnum.Top;
                        xlstStyle01.WordWrap = true;
                        xlstStyle01.Font = new Font("", 8, FontStyle.Regular);
                        xlstStyle01.SetBorderColor(Color.Black);
                        xlstStyle01.BorderBottom = XLLineStyleEnum.Thin;
                        xlstStyle01.BorderTop = XLLineStyleEnum.Thin;
                        xlstStyle01.BorderLeft = XLLineStyleEnum.Thin;
                        xlstStyle01.BorderRight = XLLineStyleEnum.Thin;

                        xlsSheet[1, 0].Value = xlsSheet[1, 0].Value.ToString().Replace("{%TOA_NHA%}", DbHelper.GetScalar("Select Name From Mst_Building Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "'"));
                        xlsSheet[1, 0].Value = xlsSheet[1, 0].Value.ToString().Replace("{%THANG%}", drpMonth.SelectedValue+"/"+drpYear.SelectedValue);

                        string seriTmp = "";
                        decimal remainTmp = 0;
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {

                            string col01 = rowType[0].ToString();
                            string col02 = rowType[1].ToString();
                            string col03 = Func.FormatDMY(rowType[2].ToString());
                            string col04 = rowType[3].ToString();
                            string col05 = rowType[4].ToString();
                            string col06 = Func.FormatDMY(rowType[5].ToString());
                            string col07 = rowType[6].ToString();
                            string col08 = rowType[7].ToString();
                            string col09 = rowType[8].ToString();
                            string col10 = rowType[9].ToString();
                            string col11 = rowType[10].ToString();
                            string col12 = rowType[11].ToString();
                            string col13 = rowType[12].ToString();

                            if (!seriTmp.Equals(col01))
                            {
                                xlsSheet[i, 0].Value = col01;
                                xlsSheet[i, 1].Value = rowType[1];
                                xlsSheet[i, 2].Value = col03;
                                xlsSheet[i, 3].Value = col04;
                                xlsSheet[i, 4].Value = col05;

                                xlsSheet[i, 0].Style = xlstStyle;
                                xlsSheet[i, 1].Style = xlstStyle;
                                xlsSheet[i, 2].Style = xlstStyle;
                                xlsSheet[i, 3].Style = xlstStyle;
                                xlsSheet[i, 4].Style = xlstStyle;

                                int remain = Func.ParseInt(col02) - Func.ParseInt(col09);
                                remainTmp = remain;
                                xlsSheet[i, 11].Value = remain;

                                seriTmp = col01;
                            }
                            else {
                                remainTmp -= Convert.ToDecimal(col09);
                                xlsSheet[i, 11].Value = remainTmp;
                            }

                            xlsSheet[i, 5].Value = col06;
                            xlsSheet[i, 6].Value = col07;
                            xlsSheet[i, 7].Value = col08;
                            xlsSheet[i, 8].Value = rowType[8];
                            xlsSheet[i, 9].Value = rowType[9];
                            xlsSheet[i, 10].Value = rowType[10];
                            xlsSheet[i,12].Value = col13;

                            xlsSheet[i, 5].Style = xlstStyle;
                            xlsSheet[i, 6].Style = xlstStyle;
                            xlsSheet[i, 7].Style = xlstStyle;
                            xlsSheet[i, 8].Style = xlstStyle;
                            xlsSheet[i, 9].Style = xlstStyle;
                            xlsSheet[i, 10].Style = xlstStyle;
                            xlsSheet[i, 11].Style = xlstStyle;
                            xlsSheet[i, 12].Style = xlstStyle;
                            ++i;
                        }

                        xlbBook.Save(fileNameDes);
                        ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true);

                    }
                }
            }
        }
Exemplo n.º 53
0
        // convert grid styles into excel styles
        static XLStyle GetXLStyle(C1FlexGrid flex, XLSheet sheet, ExcelCellStyle s)
        {
            // look it up in the cache
            XLStyle x;
            if (_excelStyles.TryGetValue(s, out x))
            {
                return x;
            }

            // not found, create style now
            x = new XLStyle(sheet.Book);

            // alignment
            if (s.HorizontalAlignment.HasValue)
            {
                switch (s.HorizontalAlignment.Value)
                {
                    case HorizontalAlignment.Left:
                        x.AlignHorz = XLAlignHorzEnum.Left;
                        break;
                    case HorizontalAlignment.Center:
                        x.AlignHorz = XLAlignHorzEnum.Center;
                        break;
                    case HorizontalAlignment.Right:
                        x.AlignHorz = XLAlignHorzEnum.Right;
                        break;
                }
            }
            if (s.VerticalAlignment.HasValue)
            {
                switch (s.VerticalAlignment.Value)
                {
                    case VerticalAlignment.Top:
                        x.AlignVert = XLAlignVertEnum.Top;
                        break;
                    case VerticalAlignment.Center:
                        x.AlignVert = XLAlignVertEnum.Center;
                        break;
                    case VerticalAlignment.Bottom:
                        x.AlignVert = XLAlignVertEnum.Bottom;
                        break;
                }
            }
            if (s.TextWrapping.HasValue)
            {
                x.WordWrap = s.TextWrapping.Value;
            }

            // colors
            if (s.Background is SolidColorBrush)
            {
                x.BackColor = ((SolidColorBrush)s.Background).Color;
                x.BackPattern = XLPatternEnum.Solid;
            }
            if (s.Foreground is SolidColorBrush)
            {
                x.ForeColor = ((SolidColorBrush)s.Foreground).Color;
            }

            // font
            var fontName = flex.FontFamily.Source;
            var fontSize = flex.FontSize;
            var bold = false;
            var italic = false;
            bool underline = false;
            bool hasFont = false;
            if (s.FontFamily != null)
            {
                fontName = s.FontFamily.Source;
                hasFont = true;
            }
            if (s.FontSize.HasValue)
            {
                fontSize = s.FontSize.Value;
                hasFont = true;
            }
            if (s.FontWeight.HasValue)
            {
                bold = s.FontWeight.Value == FontWeights.Bold ||
                    s.FontWeight.Value == FontWeights.ExtraBold ||
                    s.FontWeight.Value == FontWeights.SemiBold;
                hasFont = true;
            }
            if (s.FontStyle.HasValue)
            {
                italic = s.FontStyle.Value == FontStyles.Italic;
                hasFont = true;
            }
            if (s.TextDecorations != null)
            {
                underline = true;
                hasFont = true;
            }
            if (hasFont)
            {
                fontSize = PixelsToPoints(fontSize);
                if (underline)
                {
                    var color = Colors.Black;
                    if (flex.Foreground is SolidColorBrush)
                    {
                        color = ((SolidColorBrush)flex.Foreground).Color;
                    }
                    if (s.Foreground is SolidColorBrush)
                    {
                        color = ((SolidColorBrush)s.Foreground).Color;
                    }
                    x.Font = new XLFont(fontName, (float)fontSize, bold, italic, false, XLFontScript.None, XLUnderlineStyle.Single, color);
                }
                else
                {
                    x.Font = new XLFont(fontName, (float)fontSize, bold, italic);
                }
            }

            // format
            if (!string.IsNullOrEmpty(s.Format))
            {
                x.Format = XLStyle.FormatDotNetToXL(s.Format);
            }

            // borders
            if (s.CellBorderThickness.Left > 0 && s.CellBorderBrushLeft is SolidColorBrush)
            {
                x.BorderLeft = GetBorderLineStyle(s.CellBorderThickness.Left);
                x.BorderColorLeft = ((SolidColorBrush)s.CellBorderBrushLeft).Color;
            }
            if (s.CellBorderThickness.Top > 0 && s.CellBorderBrushTop is SolidColorBrush)
            {
                x.BorderTop = GetBorderLineStyle(s.CellBorderThickness.Top);
                x.BorderColorTop = ((SolidColorBrush)s.CellBorderBrushTop).Color;
            }
            if (s.CellBorderThickness.Right > 0 && s.CellBorderBrushRight is SolidColorBrush)
            {
                x.BorderRight = GetBorderLineStyle(s.CellBorderThickness.Right);
                x.BorderColorRight = ((SolidColorBrush)s.CellBorderBrushRight).Color;
            }
            if (s.CellBorderThickness.Bottom > 0 && s.CellBorderBrushBottom is SolidColorBrush)
            {
                x.BorderBottom = GetBorderLineStyle(s.CellBorderThickness.Bottom);
                x.BorderColorBottom = ((SolidColorBrush)s.CellBorderBrushBottom).Color;
            }

            // save in cache and return
            _excelStyles[s] = x;
            return x;
        }
Exemplo n.º 54
0
        private void btnFormulas_Click(object sender, RoutedEventArgs e)
        {
            SaveBook(book =>
            {
                // first sheet
                var sheet = book.Sheets[0];

                // column width in twips
                sheet.Columns[0].Width = 2000;
                sheet.Columns[1].Width = 2200;

                // string formulas
                string s = "String:";
                sheet[0, 0].Value = s;
                sheet[1, 0].Value = s;
                sheet[2, 0].Value = s;

                sheet[0, 1].Value = "apples";
                sheet[1, 1].Value = "and";
                sheet[2, 1].Value = "oranges";

                s = "String formula:";
                sheet[4, 0].Value = s;
                sheet[5, 0].Value = s;

                sheet[4, 1].Value = "apples and oranges";
                sheet[5, 1].Value = "apples an";
                sheet[4, 1].Formula = "CONCATENATE(B1,\" \",B2, \" \",B3)";
                sheet[5, 1].Formula = "LEFT(B5,9)";

                // simple formulas
                sheet[7, 0].Value = "Formula: 5!";
                sheet[7, 1].Value = 120;
                sheet[7, 1].Formula = "1*2*3*4*5";

                sheet[8, 0].Value = "Formula: 12/0";
                sheet[8, 1].Value = 0;
                sheet[8, 1].Formula = "12/0";

                sheet[9, 0].Value = "Formula: 1 = 1";
                sheet[9, 1].Value = true;
                sheet[9, 1].Formula = "1=1";

                sheet[10, 0].Value = "Formula: 1 = 2";
                sheet[10, 1].Value = false;
                sheet[10, 1].Formula = "1 = 2";

                // now function
                sheet[12, 0].Value = "Formula: Now()";
                sheet[12, 1].Value = DateTime.Now;
                sheet[12, 1].Formula = "Now()";

                var style = new XLStyle(book);
                var dtfi = CultureInfo.CurrentCulture.DateTimeFormat;
                style.Format = XLStyle.FormatDotNetToXL(dtfi.ShortDatePattern + " " + dtfi.ShortTimePattern);
                sheet[12, 1].Style = style;
            });
        }
Exemplo n.º 55
0
        protected void btnExport_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            string sql = string.Empty;

            sql = " SELECT *";
            sql += " FROM v_MonthParkingCount";
            sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' ";
            sql += " Order By CompanyName";

            using (SqlDatabase db = new SqlDatabase())
            {
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    db.Close();

                    if (ds != null)
                    {
                        C1XLBook xlbBook = new C1XLBook();
                        string fileName = HttpContext.Current.Server.MapPath(@"\Report\Template\THSLXT_tpl.xlsx");

                        xlbBook.Load(fileName);
                        XLSheet xlsSheet = xlbBook.Sheets["DANH SÁCH BẢO VỆ"];
                        //xlsSheet.Name = drpMonth.SelectedValue + "_" + drpYear.SelectedValue;

                        int i = 0;
                        XLCellRange mrCell = new XLCellRange(0, 0, 0, 2);
                        xlsSheet.MergedCells.Add(mrCell);

                        XLStyle xlstStyle = new XLStyle(xlbBook);
                        xlstStyle.AlignHorz = XLAlignHorzEnum.Center;
                        xlstStyle.Font = new Font("", 12, FontStyle.Bold);
                        xlstStyle.SetBorderColor(Color.Black);

                        xlsSheet[i, 0].Value = "Tháng " + drpMonth.SelectedValue + "/" + drpYear.SelectedValue;
                        xlsSheet[i, 0].Style = xlstStyle;

                        xlsSheet[i + 1, 0].Value = "STT";
                        xlsSheet[i + 1, 1].Value = "Mã Nhân Viên";
                        xlsSheet[i + 1, 2].Value = "Họ và Tên";

                        XLStyle xlstStyle01 = new XLStyle(xlbBook);
                        xlstStyle01.AlignHorz = XLAlignHorzEnum.Center;
                        xlstStyle01.Font = new Font("", 10, FontStyle.Bold);
                        xlstStyle.SetBorderColor(Color.Black);

                        for (int j = 1; j <= 31; j++)
                        {
                            //xlsSheet[i, 2 + j].Value = j;
                            //DateTime date = new DateTime(Func.ParseInt(drpYear.SelectedValue), Func.ParseInt(drpMonth.SelectedValue), j);
                            //xlsSheet[i + 1, 2 + j].Value = dictionary[date.DayOfWeek.ToString().ToLower()];

                            //xlsSheet[i, 2 + j].Style = xlstStyle01;
                            //xlsSheet[i + 1, 2 + j].Style = xlstStyle01;
                            //if (j == DateTime.DaysInMonth(Func.ParseInt(drpYear.SelectedValue), Func.ParseInt(drpMonth.SelectedValue)))
                            //{
                            //    break;
                            //}
                        }

                        //i++;
                        //DataTable dt = ds.Tables[0];
                        //foreach (DataRow rowType in dt.Rows)
                        //{
                        //    int No = i;
                        //    i++;
                        //    string StaffId = rowType["StaffId"].ToString();
                        //    string Name = rowType["Name"].ToString();

                        //    xlsSheet[i, 0].Value = No;
                        //    xlsSheet[i, 1].Value = StaffId;
                        //    xlsSheet[i, 2].Value = Name;

                        //    xlsSheet[i, 0].Style = xlstStyle01;
                        //    xlsSheet[i, 1].Style = xlstStyle01;
                        //    xlsSheet[i, 2].Style = xlstStyle01;

                        //}

                        ////ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('/CSV/DownloadZipFile.aspx'," + PopupWidth + "," + PopupHeight + ",'EditFlat', true);", true);

                        ////xlsSheet[i++, 0].Value = "Ghi chú:";
                        //DataSet ds1 = new DataSet();
                        //sql = string.Empty;

                        //sql = " SELECT *";
                        //sql += " FROM BD_WorkingHour";
                        //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and DelFlag <> 1";
                        //sql += " Order By Name";

                        //using (SqlCommand cm1 = db.CreateCommand(sql))
                        //{
                        //    SqlDataAdapter da1 = new SqlDataAdapter(cm1);
                        //    da1.Fill(ds1);
                        //    db.Close();

                        //    if (ds != null)
                        //    {

                        //        xlsSheet[i++ + 1, 0].Value = "Ghi chú:";
                        //        DataTable dt1 = ds1.Tables[0];
                        //        foreach (DataRow rowType in dt1.Rows)
                        //        {
                        //            i++;
                        //            string Ma = rowType["WorkingHourId"].ToString();
                        //            string Name = rowType["Name"].ToString();
                        //            xlsSheet[i, 0].Value = Ma + ":";
                        //            xlsSheet[i, 1].Value = Name;
                        //        }
                        //        xlsSheet[i + 1, 0].Value = "OF:";
                        //        xlsSheet[i + 1, 1].Value = "OF: nghỉ";
                        //    }
                        //}
                        //string dataPath = HttpContext.Current.Server.MapPath(@"\Building\Staff\DataTmp");
                        //string tmpFolder = dataPath;
                        //if (!Directory.Exists(tmpFolder))
                        //{
                        //    Directory.CreateDirectory(tmpFolder);
                        //}
                        //string name = "KhaiBaoLichLamViec_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls";
                        //string fileName = Path.Combine(tmpFolder, name);
                        string fileName1 = HttpContext.Current.Server.MapPath(@"\Report\Template\THSLXT_tpl_1.xlsx");

                        xlbBook.Save(fileName1);
                        //Session["ZipFilePath"] = null;
                        //Session["ZipFilePath"] = fileName;

                        //ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../Staff/DataTmp/" + name + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true);

                    }
                }
            }
        }
Exemplo n.º 56
0
        protected void btnExport_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            string sql = string.Empty;

            sql = " SELECT  A.GroupName, B.MaintenanceItem, B.ScheduleDate";
            sql += " FROM    BD_SuppliesGroup AS A Left outer JOIN";
            sql += "         BD_SuppliesGroupMaintenance AS B ON A.id = B.SuppliesGroupId";
            sql += "         and substring(ScheduleDate,1,4) = '" + drpYear.SelectedValue + "'";
            sql += " and B.DelFlag = 0 Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.SuppliesType = '" + hidSuppliesType.Value + "'";
            sql += " Order by GroupName, MaintenanceItem";

            using (SqlDatabase db = new SqlDatabase())
            {
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    if (ds != null)
                    {
                        C1XLBook xlbBook = new C1XLBook();
                        XLStyle xlstStyle = new XLStyle(xlbBook);
                        xlstStyle.AlignHorz = XLAlignHorzEnum.Left;
                        xlstStyle.AlignVert = XLAlignVertEnum.Center;
                        xlstStyle.WordWrap = true;
                        xlstStyle.Font = new Font("", 8, FontStyle.Regular);
                        xlstStyle.SetBorderColor(Color.Black);
                        xlstStyle.BorderBottom = XLLineStyleEnum.Thin;
                        xlstStyle.BorderTop = XLLineStyleEnum.Thin;
                        xlstStyle.BorderLeft = XLLineStyleEnum.Thin;
                        xlstStyle.BorderRight = XLLineStyleEnum.Thin;

                        XLStyle xlstStyleS = new XLStyle(xlbBook);
                        xlstStyleS.AlignHorz = XLAlignHorzEnum.Left;
                        xlstStyleS.AlignVert = XLAlignVertEnum.Center;
                        xlstStyleS.WordWrap = true;
                        xlstStyleS.Font = new Font("", 8, FontStyle.Regular);
                        xlstStyleS.SetBorderColor(Color.Black);
                        xlstStyleS.BorderBottom = XLLineStyleEnum.Thin;
                        xlstStyleS.BorderTop = XLLineStyleEnum.Thin;
                        xlstStyleS.BorderLeft = XLLineStyleEnum.Thin;
                        xlstStyleS.BorderRight = XLLineStyleEnum.Thin;
                        xlstStyleS.BackColor = Color.Red;

                        string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\BaoTriDinhKy.xls");
                        if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BaoTriDinhKy"))
                        {
                            Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BaoTriDinhKy"));
                        }

                        string strDT = DateTime.Now.ToString("yyyyMMddHHmmss");
                        string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BaoTriDinhKy\BaoTriDinhKy" + strDT + ".xls";
                        string strFilePathExport = "../../Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + "/BaoTriDinhKy/BaoTriDinhKy" + strDT + ".xls";

                        string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath);

                        File.Copy(fileName, fileNameDes);

                        xlbBook.Load(fileNameDes);

                        XLSheet xlsSheet = xlbBook.Sheets["BaoTri"];
                        xlsSheet[1, 0].Value = xlsSheet[1, 0].Value.ToString().Replace("{%NAM%}", drpYear.SelectedValue);

                        int stt = 0;
                        XLCellRange mCell = new XLCellRange(0, 0, 0, 0);

                        int i = 4;
                        DataTable dt = ds.Tables[0];
                        string tmpMaintenanceItem = "";
                        foreach (DataRow rowType in dt.Rows)
                        {
                            string GroupName = rowType["GroupName"].ToString();
                            string MaintenanceItem = rowType["MaintenanceItem"].ToString();
                            string ScheduleDate = rowType["ScheduleDate"].ToString();
                            if (String.IsNullOrEmpty(tmpMaintenanceItem))
                            {
                                tmpMaintenanceItem = GroupName + MaintenanceItem;
                                i++;
                            }

                            if (!tmpMaintenanceItem.Equals(GroupName + MaintenanceItem))
                            {
                                i++;
                                tmpMaintenanceItem = GroupName + MaintenanceItem;
                            }

                            xlsSheet[i, 1].Value = GroupName;
                            xlsSheet[i, 2].Value = MaintenanceItem;

                            mCell = new XLCellRange(i, i, 2, 3);
                            xlsSheet.MergedCells.Add(mCell);

                            xlsSheet[i, 1].Style = xlstStyle;
                            xlsSheet[i, 2].Style = xlstStyle;

                            for (int m = 0; m <= 51; m++)
                            {
                                xlsSheet[i, m].Style = xlstStyle;
                                if ("X".Equals(xlsSheet[i, m].Value))
                                {
                                    xlsSheet[i, m].Style = xlstStyleS;
                                }
                            }

                            if (!String.IsNullOrEmpty(ScheduleDate))
                            {
                                int month = Func.ParseInt(ScheduleDate.Substring(4, 2));
                                int date = Func.ParseInt(ScheduleDate.Substring(6, 2));
                                int x = month * 4;
                                if (date >= 1 && date <= 7)
                                    x += 0;
                                if (date >= 8 && date <= 14)
                                    x += 1;
                                if (date >= 15 && date <= 21)
                                    x += 2;
                                if (date >= 22 && date <= 31)
                                    x += 3;
                                xlsSheet[i, x].Value = "X";
                                xlsSheet[i, x].Style = xlstStyleS;
                            }

                        }

                        i = 5;
                        int k = 1;
                        string tmp = xlsSheet[i, 1].Value.ToString();
                        xlsSheet[i, 0].Value = k;
                        int y = i;
                        i++;
                        mCell = new XLCellRange(0, 0, 0, 0); ;
                        while (!String.IsNullOrEmpty(Func.ParseString(xlsSheet[i, 1].Value)))
                        {
                            if (xlsSheet[i, 1].Value.ToString() != tmp)
                            {
                                tmp = xlsSheet[i, 1].Value.ToString();
                                mCell = new XLCellRange(y, i - 1, 1, 1);
                                xlsSheet.MergedCells.Add(mCell);

                                mCell = new XLCellRange(y, i - 1, 0, 0);
                                xlsSheet.MergedCells.Add(mCell);

                                y = i;
                                xlsSheet[i, 0].Value = ++k;
                            }
                            i++;
                        }
                        mCell = new XLCellRange(y, i - 1, 1, 1);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(y, i - 1, 0, 0);
                        xlsSheet.MergedCells.Add(mCell);

                        xlbBook.Save(fileNameDes);
                        ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('../" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true);

                    }
                }
            }
        }
Exemplo n.º 57
0
        private void btnStyles_Click(object sender, RoutedEventArgs e)
        {
            SaveBook(book =>
            {
                // get the sheet that was created by default, give it a name
                var sheet = book.Sheets[0];

                // create styles for odd and even values
                var styleOdd = new XLStyle(book);
                styleOdd.Font = new XLFont("Tahoma", 9, false, true);
                styleOdd.ForeColor = Colors.Blue;

                var styleEven = new XLStyle(book);
                styleEven.Font = new XLFont("Tahoma", 9, true, false);
                styleEven.ForeColor = Colors.Red;
                styleEven.BackColor = Colors.Yellow;

                // step 3: write content and format into some cells
                for (int i = 0; i < 30; i++)
                {
                    XLCell cell = sheet[i, 0];
                    cell.Value = i + 1;
                    cell.Style = ((i + 1) % 2 == 0) ? styleEven : styleOdd;
                }
            });
        }
        public void ViewMultiBoth(string lsYearmonth)
        {
            //string lsYearmonth = "";
            //foreach (ListItem lstItem in lstSelectedYearMonth.Items)
            //{
            //    lsYearmonth += ",'" + lstItem.Value + "'";

            //    if (String.Compare(DateTime.Now.ToString("yyyyMMdd"), lstItem.Value) < 0)
            //    {
            //        using (SqlConnection con = new SqlConnection(Gnt.Configuration.ApplicationConfiguration.ConnectionString))
            //        {
            //            con.Open();
            //            using (SqlCommand cm = new SqlCommand("sp_PaymentDetailOneCustomerRentManager", con))
            //            {
            //                try
            //                {
            //                    cm.CommandType = CommandType.StoredProcedure;
            //                    cm.Parameters.AddWithValue("@BuildingId", Func.ParseString(Session["__BUILDINGID__"]));
            //                    cm.Parameters.AddWithValue("@CustomerId", lblCustomerId.Text);
            //                    cm.Parameters.AddWithValue("@YearMonth", lstItem.Value);
            //                    cm.Parameters.AddWithValue("@Created", DateTime.Now.ToString("yyyyMMddHHmmss"));
            //                    cm.Parameters.AddWithValue("@CreatedBy", Page.User.Identity.Name);
            //                    cm.Parameters.AddWithValue("@Modified", DateTime.Now.ToString("yyyyMMddHHmmss"));
            //                    cm.Parameters.AddWithValue("@ModifiedBy", Page.User.Identity.Name);

            //                    cm.CommandTimeout = 9999;

            //                    int ret = cm.ExecuteNonQuery();
            //                }
            //                catch (Exception ex)
            //                {
            //                    ApplicationLog.WriteError(ex);
            //                }
            //                finally
            //                {
            //                    con.Close();
            //                }
            //            }
            //        }
            //    }
            //}
            if (String.IsNullOrEmpty(lsYearmonth))
            {
                mvMessage.AddError("Phải chọn ít nhất 1 tháng");
                return;
            }
            //lsYearmonth = lsYearmonth.Substring(1);

            int rBillNo = 0;
            int cBillNo = 1;

            int rBillDate = 0;
            int cBillDate = 10;

            int rBillMonth = 2;
            int cBillMonth = 0;

            int rContact = 5;
            int cContact = 3;

            int rCustomer = 5;
            int cCustomer = 7;

            int rContract = 7;
            int cContract = 1;

            int rRate = 11;
            int cRate = 9;

            int rRateDate = 11;
            int cRateDate = 12;

            int rRent = 15;

            int rManager = 23;

            int rParking = 31;

            int rExtra = 39;

            int rElec = 47;

            int rWater = 55;

            int rService = 63;

            int rPaid = 70;

            int rDept = 77;

            int rOffice = 88;
            int cOffice = 3;

            int rPhone = 89;
            int cPhone = 3;

            int rBank = 88;
            int cBank = 7;

            int rAccountName = 89;
            int cAccountName = 7;

            int rAccount = 90;
            int cAccount = 7;

            int rSum = 81;
            int cSum = 12;

            int rSumVND = 80;
            int cSumVND = 12;

            int rSumRead = 82;
            int cSumRead = 13;

            int check = DbHelper.GetCount("Select count(*) from PaymentBillInfo Where BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + lblCustomerId.Text + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'");
            if (check == 0)
            {
                mvMessage.AddError("Xin vui lòng tạo hóa đơn trước khi xem");
                return;
            }
            mvMessage.CheckRequired(txtBillDate, "Ngày xuất Hóa đơn là danh mục bắt buộc");
            mvMessage.CheckRequired(txtBillNo, "Số Hóa đơn là danh mục bắt buộc");
            mvMessage.CheckRequired(txtUsdExchange, "Tỉ giá USD-VN là danh mục bắt buộc");
            mvMessage.CheckRequired(txtUsdExchangeDate, "Ngày tỉ giá là danh mục bắt buộc");
            //ShowData(drpYear.SelectedValue + drpMonth.SelectedValue);
            C1XLBook xlbBook = new C1XLBook();
            string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\BillTongQuat.xlsx");
            if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"])))
            {
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"])));
            }

            XLStyle xlstStyle = new XLStyle(xlbBook);
            xlstStyle.AlignHorz = XLAlignHorzEnum.Center;
            xlstStyle.AlignVert = XLAlignVertEnum.Center;
            xlstStyle.WordWrap = true;
            xlstStyle.Font = new Font("Times New Roman", 12, FontStyle.Regular);
            xlstStyle.SetBorderColor(Color.Black);
            xlstStyle.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyle.BorderTop = XLLineStyleEnum.Thin;
            xlstStyle.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyle.BorderRight = XLLineStyleEnum.Thin;
            xlstStyle.Format = "#,##0.00_);(#,##0.00)";

            XLStyle xlstStyleH = new XLStyle(xlbBook);
            xlstStyleH.AlignHorz = XLAlignHorzEnum.Center;
            xlstStyleH.AlignVert = XLAlignVertEnum.Center;
            xlstStyleH.Font = new Font("Times New Roman", 12, FontStyle.Bold);
            xlstStyleH.SetBorderColor(Color.Black);
            xlstStyleH.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyleH.BorderTop = XLLineStyleEnum.Thin;
            xlstStyleH.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyleH.BorderRight = XLLineStyleEnum.Thin;
            xlstStyleH.WordWrap = true;

            XLStyle xlstStyleSum = new XLStyle(xlbBook);
            xlstStyleSum.AlignHorz = XLAlignHorzEnum.Right;
            xlstStyleSum.AlignVert = XLAlignVertEnum.Center;
            xlstStyleSum.Font = new Font("Times New Roman", 12, FontStyle.Bold);
            xlstStyleSum.SetBorderColor(Color.Black);
            xlstStyleSum.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyleSum.BorderTop = XLLineStyleEnum.Thin;
            xlstStyleSum.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyleSum.BorderRight = XLLineStyleEnum.Thin;
            xlstStyleSum.WordWrap = true;
            xlstStyleSum.Format = "#,##0.00_);(#,##0.00)";

            string strDT = DateTime.Now.ToString("yyyyMMddHHmmss");
            string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\Bill_" + lblCustomerId.Text + "_" + strDT + ".xlsx";
            string strFilePathExport = @"../../Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + @"/Bill_" + lblCustomerId.Text + "_" + strDT + ".xlsx";

            string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath);

            //string fileNameDes = HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\TongHopDienTich" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
            File.Copy(fileName, fileNameDes);

            xlbBook.Load(fileNameDes);
            XLSheet xlsSheet = xlbBook.Sheets["TongHop"];
            XLSheet xlsSheetEn = xlbBook.Sheets["TongHop_En"];

            //Bill No
            xlsSheet[rBillNo, cBillNo].Value = xlsSheet[rBillNo, cBillNo].Value.ToString().Replace("{%BILL_NO%}", txtBillNo.Text);
            xlsSheetEn[rBillNo, cBillNo].Value = xlsSheetEn[rBillNo, cBillNo].Value.ToString().Replace("{%BILL_NO%}", txtBillNo.Text);

            //Ngay Thang Nam
            DateTime dtime = DateTime.Today;

            string strTmp = xlsSheet[rBillDate, cBillDate].Value.ToString().Replace("{%NGAY%}", dtime.ToString("dd"));
            strTmp = strTmp.Replace("{%THANG%}", dtime.ToString("MM"));
            xlsSheet[rBillDate, cBillDate].Value = strTmp.Replace("{%NAM%}", dtime.ToString("yyyy"));

            strTmp = xlsSheetEn[rBillDate, cBillDate].Value.ToString().Replace("{%NGAY%}", dtime.ToString("dd"));
            strTmp = strTmp.Replace("{%THANG%}", dtime.ToString("MM"));
            xlsSheetEn[rBillDate, cBillDate].Value = strTmp.Replace("{%NAM%}", dtime.ToString("yyyy"));

            //Nam
            xlsSheet[rBillMonth, cBillMonth].Value = xlsSheet[rBillMonth, cBillMonth].Value.ToString().Replace("{%NAM_THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue);
            xlsSheetEn[rBillMonth, cBillMonth].Value = xlsSheetEn[rBillMonth, cBillMonth].Value.ToString().Replace("{%NAM_THANG%}", drpMonth.SelectedValue + "/" + drpYear.SelectedValue);

            using (SqlDatabase db = new SqlDatabase())
            {
                DataSet ds = new DataSet();
                string sql = string.Empty;

                sql = " SELECT Name, ContactName";
                sql += " FROM Customer";
                sql += " WHERE CustomerId = '" + lblCustomerId.Text + "' ";

                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    if (ds != null)
                    {
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            string Name = rowType[0].ToString();
                            string ContactName = rowType[1].ToString();

                            //Customer
                            xlsSheet[rCustomer, cCustomer].Value = xlsSheet[rCustomer, cCustomer].Value.ToString().Replace("{%TEN_CONG_TY%}", Name);
                            xlsSheetEn[rCustomer, cCustomer].Value = xlsSheetEn[rCustomer, cCustomer].Value.ToString().Replace("{%TEN_CONG_TY%}", Name);
                            //Contact
                            xlsSheet[rContact, cContact].Value = xlsSheet[rContact, cContact].Value.ToString().Replace("{%NGUOI_DAI_DIEN%}", ContactName);
                            xlsSheetEn[rContact, cContact].Value = xlsSheetEn[rContact, cContact].Value.ToString().Replace("{%NGUOI_DAI_DIEN%}", ContactName);
                        }
                    }
                }
                Hashtable contractIdLst = new Hashtable();
                string contract = "";
                ds = new DataSet();
                sql = " SELECT Bank,Account,AccountName,Office,OfficeAddress,OfficePhone";
                sql += " FROM Mst_Building";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' ";
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    if (ds != null)
                    {
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            string Bank = rowType["Bank"].ToString();
                            string Account = rowType["Account"].ToString();
                            string AccountName = rowType["AccountName"].ToString();
                            string Office = rowType["Office"].ToString();
                            string OfficeAddress = rowType["OfficeAddress"].ToString();
                            string OfficePhone = rowType["OfficePhone"].ToString();

                            xlsSheet[rOffice, cOffice].Value = xlsSheet[rOffice, cOffice].Value.ToString().Replace("{%VAN_PHONG%}", Office);
                            xlsSheet[rPhone, cPhone].Value = xlsSheet[rPhone, cPhone].Value.ToString().Replace("{%DIEN_THOAI%}", OfficePhone);

                            xlsSheet[rBank, cBank].Value = xlsSheet[rBank, cBank].Value.ToString().Replace("{%NGAN_HANG%}", Bank);
                            xlsSheet[rAccountName, cAccountName].Value = xlsSheet[rAccountName, cAccountName].Value.ToString().Replace("{%TEN_TAI_KHOAN%}", AccountName);
                            xlsSheet[rAccount, cAccount].Value = xlsSheet[rAccount, cAccount].Value.ToString().Replace("{%SO_TAI_KHOAN%}", Account);

                            xlsSheetEn[rOffice, cOffice].Value = xlsSheetEn[rOffice, cOffice].Value.ToString().Replace("{%VAN_PHONG%}", Office);
                            xlsSheetEn[rPhone, cPhone].Value = xlsSheetEn[rPhone, cPhone].Value.ToString().Replace("{%DIEN_THOAI%}", OfficePhone);

                            xlsSheetEn[rBank, cBank].Value = xlsSheetEn[rBank, cBank].Value.ToString().Replace("{%NGAN_HANG%}", Bank);
                            xlsSheetEn[rAccountName, cAccountName].Value = xlsSheetEn[rAccountName, cAccountName].Value.ToString().Replace("{%TEN_TAI_KHOAN%}", AccountName);
                            xlsSheetEn[rAccount, cAccount].Value = xlsSheetEn[rAccount, cAccount].Value.ToString().Replace("{%SO_TAI_KHOAN%}", Account);
                        }
                    }
                }

                xlsSheet[rRate, cRate].Value = xlsSheet[rRate, cRate].Value.ToString().Replace("{%TI_GIA%}", txtUsdExchange.Text);
                xlsSheet[rRateDate, cRateDate].Value = xlsSheet[rRateDate, cRateDate].Value.ToString().Replace("{%NGAY_AP_DUNG%}", txtUsdExchangeDate.Text);

                xlsSheetEn[rRate, cRate].Value = xlsSheetEn[rRate, cRate].Value.ToString().Replace("{%TI_GIA%}", txtUsdExchange.Text);
                xlsSheetEn[rRateDate, cRateDate].Value = xlsSheetEn[rRateDate, cRateDate].Value.ToString().Replace("{%NGAY_AP_DUNG%}", txtUsdExchangeDate.Text);

                //Thue phong
                ds = new DataSet();
                sql = " Select *";
                sql += " FROM PaymentRoom";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth in (" + lsYearmonth + ")";

                int sumRow = 0;
                int j = 0;
                decimal[] LastSumPriceVND = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 };
                decimal[] LastSumPriceUSD = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 };

                decimal PaidPriceVND = 0;
                decimal PaidPriceUSD = 0;

                int line = 0;
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    line = rRent - 3 + j;

                    XLCellRange mCell = new XLCellRange(line, line + 2, 1, 3);
                    xlsSheet.MergedCells.Add(mCell);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 4, 5);
                    xlsSheet.MergedCells.Add(mCell);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 4, 5);
                    xlsSheet.MergedCells.Add(mCell);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 2, line + 2, 4, 5);
                    xlsSheet.MergedCells.Add(mCell);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 6, 7);
                    xlsSheet.MergedCells.Add(mCell);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 6, 7);
                    xlsSheet.MergedCells.Add(mCell);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 8, 9);
                    xlsSheet.MergedCells.Add(mCell);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 8, 9);
                    xlsSheet.MergedCells.Add(mCell);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 10, 11);
                    xlsSheet.MergedCells.Add(mCell);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 10, 11);
                    xlsSheet.MergedCells.Add(mCell);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);
                    xlsSheetEn.MergedCells.Add(mCell);

                    if (ds != null)
                    {
                        int count = 0;
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            if (count >= 1)
                            {
                                xlsSheet.Rows.Insert(rRent + 1 + j);
                                xlsSheetEn.Rows.Insert(rRent + 1 + j);
                                j++;
                            }
                            count++;
                            int tmp = rRent + j;

                            string ContractId = Func.ParseString(rowType["ContractId"]);
                            string ContractNo = Func.ParseString(rowType["ContractNo"]);
                            string YearMonth = Func.ParseString(rowType["YearMonth"]);
                            string Area = Func.ParseString(rowType["Area"]);
                            string Name = Func.ParseString(rowType["Name"]);
                            string Regional = Func.ParseString(rowType["Regional"]);
                            string Floor = Func.ParseString(rowType["Floor"]);

                            string BeginContract = Func.ParseString(rowType["BeginContract"]);

                            if (!contractIdLst.ContainsKey(ContractId + "(" + BeginContract.Substring(0, 10) + ")"))
                            {
                                contractIdLst.Add(ContractId + "(" + BeginContract.Substring(0, 10) + ")", ContractNo + "(" + BeginContract.Substring(0, 10) + ")");
                                contract += ";" + ContractNo + "(" + BeginContract.Substring(0, 10) + ")";
                            }

                            xlsSheet[tmp, 1].Value = Name;
                            xlsSheet[tmp, 4].Value = rowType["Area"];
                            xlsSheet[tmp, 6].Value = rowType["MonthRentPriceUSD"];
                            xlsSheet[tmp, 7].Value = rowType["MonthRentPriceVND"];

                            xlsSheet[tmp, 8].Value = rowType["MonthRentSumUSD"];
                            xlsSheet[tmp, 9].Value = rowType["MonthRentSumVND"];

                            xlsSheet[tmp, 10].Value = rowType["VatRentPriceUSD"];
                            xlsSheet[tmp, 11].Value = rowType["VatRentPriceVND"];

                            xlsSheet[tmp, 12].Value = rowType["LastRentSumUSD"];
                            xlsSheet[tmp, 13].Value = rowType["LastRentSumVND"];

                            XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3);
                            xlsSheet.MergedCells.Add(mrCell);

                            mrCell = new XLCellRange(tmp, tmp, 4, 5);
                            xlsSheet.MergedCells.Add(mrCell);

                            ////EN
                            xlsSheetEn[tmp, 1].Value = Name;
                            xlsSheetEn[tmp, 4].Value = rowType["Area"];
                            xlsSheetEn[tmp, 6].Value = rowType["MonthRentPriceUSD"];
                            xlsSheetEn[tmp, 7].Value = rowType["MonthRentPriceVND"];

                            xlsSheetEn[tmp, 8].Value = rowType["MonthRentSumUSD"];
                            xlsSheetEn[tmp, 9].Value = rowType["MonthRentSumVND"];

                            xlsSheetEn[tmp, 10].Value = rowType["VatRentPriceUSD"];
                            xlsSheetEn[tmp, 11].Value = rowType["VatRentPriceVND"];

                            xlsSheetEn[tmp, 12].Value = rowType["LastRentSumUSD"];
                            xlsSheetEn[tmp, 13].Value = rowType["LastRentSumVND"];

                            mrCell = new XLCellRange(tmp, tmp, 1, 3);
                            xlsSheetEn.MergedCells.Add(mrCell);

                            mrCell = new XLCellRange(tmp, tmp, 4, 5);
                            xlsSheetEn.MergedCells.Add(mrCell);
                            ////EN

                            LastSumPriceVND[0] += Convert.ToDecimal(rowType["LastRentSumVND"]);
                            LastSumPriceUSD[0] += Convert.ToDecimal(rowType["LastRentSumUSD"]);

                        }
                        mCell = new XLCellRange(rRent + 1 + j, rRent + 1 + j, 1, 11);
                        xlsSheet.MergedCells.Add(mCell);
                        xlsSheetEn.MergedCells.Add(mCell);

                        xlsSheet[rRent + 1 + j, 12].Value = LastSumPriceUSD[0];
                        xlsSheet[rRent + 1 + j, 13].Value = LastSumPriceVND[0];

                        xlsSheetEn[rRent + 1 + j, 12].Value = LastSumPriceUSD[0];
                        xlsSheetEn[rRent + 1 + j, 13].Value = LastSumPriceVND[0];

                        for (int row = rRent + sumRow; row <= rRent + dt.Rows.Count; row++)
                        {
                            for (int col = 1; col <= 13; col++)
                            {
                                xlsSheet[row, col].Style = xlstStyle;
                                xlsSheetEn[row, col].Style = xlstStyle;
                            }
                        }
                        sumRow += dt.Rows.Count - 1;

                        ////////////////////////
                        for (int col = 1; col <= 13; col++)
                        {
                            xlsSheet[rRent + 1 + j, col].Style = xlstStyleSum;
                            xlsSheetEn[rRent + 1 + j, col].Style = xlstStyleSum;
                        }
                        line = rManager - 3 + j;
                        mCell = new XLCellRange(line, line + 2, 1, 3);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line, line, 4, 5);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line + 1, line + 1, 4, 5);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line + 2, line + 2, 4, 5);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line, line, 6, 7);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line + 1, line + 1, 6, 7);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line, line, 8, 9);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line + 1, line + 1, 8, 9);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line, line, 10, 11);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line + 1, line + 1, 10, 11);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line, line, 12, 13);
                        xlsSheet.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line + 1, line + 1, 12, 13);
                        xlsSheet.MergedCells.Add(mCell);

                        ////En
                        mCell = new XLCellRange(line, line + 2, 1, 3);
                        xlsSheetEn.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line, line, 4, 5);
                        xlsSheetEn.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line + 1, line + 1, 4, 5);
                        xlsSheetEn.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line + 2, line + 2, 4, 5);
                        xlsSheetEn.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line, line, 6, 7);
                        xlsSheetEn.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line + 1, line + 1, 6, 7);
                        xlsSheetEn.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line, line, 8, 9);
                        xlsSheetEn.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line + 1, line + 1, 8, 9);
                        xlsSheetEn.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line, line, 10, 11);
                        xlsSheetEn.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line + 1, line + 1, 10, 11);
                        xlsSheetEn.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line, line, 12, 13);
                        xlsSheetEn.MergedCells.Add(mCell);

                        mCell = new XLCellRange(line + 1, line + 1, 12, 13);
                        xlsSheetEn.MergedCells.Add(mCell);
                        ////En
                        count = 0;
                        foreach (DataRow row in dt.Rows)
                        {
                            if (count >= 1)
                            {
                                xlsSheet.Rows.Insert(rManager + 1 + j);
                                xlsSheetEn.Rows.Insert(rManager + 1 + j);
                                j++;
                            }
                            count++;
                            int tmp = rManager + j;

                            string YearMonth = Func.ParseString(row["YearMonth"]);
                            string Area = Func.ParseString(row["Area"]);
                            string Name = Func.ParseString(row["Name"]);

                            xlsSheet[tmp, 1].Value = Name;
                            xlsSheet[tmp, 4].Value = row["Area"];
                            xlsSheet[tmp, 6].Value = row["MonthManagerPriceUSD"];
                            xlsSheet[tmp, 7].Value = row["MonthManagerPriceVND"];

                            xlsSheet[tmp, 8].Value = row["MonthManagerSumUSD"];
                            xlsSheet[tmp, 9].Value = row["MonthManagerSumVND"];

                            xlsSheet[tmp, 19].Value = row["VatManagerPriceUSD"];
                            xlsSheet[tmp, 11].Value = row["VatManagerPriceVND"];

                            xlsSheet[tmp, 12].Value = row["LastManagerSumUSD"];
                            xlsSheet[tmp, 13].Value = row["LastManagerSumVND"];

                            XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3);
                            xlsSheet.MergedCells.Add(mrCell);

                            mrCell = new XLCellRange(tmp, tmp, 4, 5);
                            xlsSheet.MergedCells.Add(mrCell);

                            ////En
                            xlsSheetEn[tmp, 1].Value = Name;
                            xlsSheetEn[tmp, 4].Value = row["Area"];
                            xlsSheetEn[tmp, 6].Value = row["MonthManagerPriceUSD"];
                            xlsSheetEn[tmp, 7].Value = row["MonthManagerPriceVND"];

                            xlsSheetEn[tmp, 8].Value = row["MonthManagerSumUSD"];
                            xlsSheetEn[tmp, 9].Value = row["MonthManagerSumVND"];

                            xlsSheetEn[tmp, 19].Value = row["VatManagerPriceUSD"];
                            xlsSheetEn[tmp, 11].Value = row["VatManagerPriceVND"];

                            xlsSheetEn[tmp, 12].Value = row["LastManagerSumUSD"];
                            xlsSheetEn[tmp, 13].Value = row["LastManagerSumVND"];

                            mrCell = new XLCellRange(tmp, tmp, 1, 3);
                            xlsSheetEn.MergedCells.Add(mrCell);

                            mrCell = new XLCellRange(tmp, tmp, 4, 5);
                            xlsSheetEn.MergedCells.Add(mrCell);
                            ////En
                            LastSumPriceVND[1] += Convert.ToDecimal(row["LastManagerSumVND"]);
                            LastSumPriceUSD[1] += Convert.ToDecimal(row["LastManagerSumUSD"]);
                        }
                        mCell = new XLCellRange(rManager + 1 + j, rManager + 1 + j, 1, 11);
                        xlsSheet.MergedCells.Add(mCell);
                        xlsSheetEn.MergedCells.Add(mCell);

                        xlsSheet[rManager + 1 + j, 12].Value = LastSumPriceUSD[1];
                        xlsSheet[rManager + 1 + j, 13].Value = LastSumPriceVND[1];

                        xlsSheetEn[rManager + 1 + j, 12].Value = LastSumPriceUSD[1];
                        xlsSheetEn[rManager + 1 + j, 13].Value = LastSumPriceVND[1];

                        for (int row = rManager + sumRow; row <= rManager + sumRow + dt.Rows.Count; row++)
                        {
                            for (int col = 1; col <= 13; col++)
                            {
                                xlsSheet[row, col].Style = xlstStyle;
                                xlsSheetEn[row, col].Style = xlstStyle;
                            }
                        }

                        for (int col = 1; col <= 13; col++)
                        {
                            xlsSheet[rManager + 1 + j, col].Style = xlstStyleSum;
                            xlsSheetEn[rManager + 1 + j, col].Style = xlstStyleSum;
                        }
                        sumRow += dt.Rows.Count - 1;
                    }
                }

                ds = new DataSet();
                //Xuất ra toàn bộ nội dung theo Trang
                sql = " SELECT COUNT(*) AS Num, YearMonth, TariffsParkingName, PriceVND, PriceUSD, SUM(VatVND) AS VatVND,SUM(VatUSD) AS VatUSD, SUM(SumVND) AS SumVND, SUM(SumUSD) AS SumUSD, SUM(LastPriceVND) AS LastPriceVND";
                sql += "        , SUM(LastPriceUSD) AS LastPriceUSD";
                sql += " FROM         dbo.PaymentParking";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth in (" + lsYearmonth + ")";
                sql += " GROUP BY YearMonth, TariffsParkingName, PriceVND, PriceUSD, Vat, daysParking";

                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    line = rParking - 3 + j;
                    XLCellRange mCell = new XLCellRange(line, line + 2, 1, 3);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 4, 5);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 4, 5);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 2, line + 2, 4, 5);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 6, 7);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 6, 7);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 8, 9);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 8, 9);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 10, 11);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 10, 11);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);

                    ////En
                    mCell = new XLCellRange(line, line + 2, 1, 3);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 4, 5);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 4, 5);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 2, line + 2, 4, 5);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 6, 7);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 6, 7);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 8, 9);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 8, 9);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 10, 11);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 10, 11);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 12, 13);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 12, 13);
                    xlsSheetEn.MergedCells.Add(mCell);
                    ////En
                    if (ds != null)
                    {
                        int count = 0;
                        DataTable dt = ds.Tables[0];

                        foreach (DataRow row in dt.Rows)
                        {
                            if (count >= 1)
                            {
                                xlsSheet.Rows.Insert(rParking + 1 + j);
                                xlsSheetEn.Rows.Insert(rParking + 1 + j);
                                j++;
                            }
                            count++;
                            int tmp = rParking + j;

                            string Num = Func.ParseString(row["Num"]);
                            string TariffsParkingName = Func.ParseString(row["TariffsParkingName"]);

                            xlsSheet[tmp, 1].Value = TariffsParkingName;
                            xlsSheet[tmp, 4].Value = Num;
                            xlsSheet[tmp, 6].Value = row["PriceUSD"];
                            xlsSheet[tmp, 7].Value = row["PriceVND"];

                            xlsSheet[tmp, 8].Value = row["SumUSD"];
                            xlsSheet[tmp, 9].Value = row["SumVND"];

                            xlsSheet[tmp, 10].Value = row["VatUSD"];
                            xlsSheet[tmp, 11].Value = row["VatVND"];

                            xlsSheet[tmp, 12].Value = row["LastPriceUSD"];
                            xlsSheet[tmp, 13].Value = row["LastPriceVND"];

                            XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3);
                            xlsSheet.MergedCells.Add(mrCell);

                            mrCell = new XLCellRange(tmp, tmp, 4, 5);
                            xlsSheet.MergedCells.Add(mrCell);

                            /////En
                            xlsSheetEn[tmp, 1].Value = TariffsParkingName;
                            xlsSheetEn[tmp, 4].Value = Num;
                            xlsSheetEn[tmp, 6].Value = row["PriceUSD"];
                            xlsSheetEn[tmp, 7].Value = row["PriceVND"];

                            xlsSheetEn[tmp, 8].Value = row["SumUSD"];
                            xlsSheetEn[tmp, 9].Value = row["SumVND"];

                            xlsSheetEn[tmp, 10].Value = row["VatUSD"];
                            xlsSheetEn[tmp, 11].Value = row["VatVND"];

                            xlsSheetEn[tmp, 12].Value = row["LastPriceUSD"];
                            xlsSheetEn[tmp, 13].Value = row["LastPriceVND"];

                            mrCell = new XLCellRange(tmp, tmp, 1, 3);
                            xlsSheetEn.MergedCells.Add(mrCell);

                            mrCell = new XLCellRange(tmp, tmp, 4, 5);
                            xlsSheetEn.MergedCells.Add(mrCell);
                            /////En
                            LastSumPriceVND[2] += Convert.ToDecimal(row["LastPriceVND"]);
                            LastSumPriceUSD[2] += Convert.ToDecimal(row["LastPriceUSD"]);
                        }
                        xlsSheet[rParking + 1 + j, 12].Value = LastSumPriceUSD[2];
                        xlsSheet[rParking + 1 + j, 13].Value = LastSumPriceVND[2];

                        mCell = new XLCellRange(rParking + 1 + j, rParking + 1 + j, 1, 11);
                        xlsSheet.MergedCells.Add(mCell);

                        /////En
                        xlsSheetEn[rParking + 1 + j, 12].Value = LastSumPriceUSD[2];
                        xlsSheetEn[rParking + 1 + j, 13].Value = LastSumPriceVND[2];

                        mCell = new XLCellRange(rParking + 1 + j, rParking + 1 + j, 1, 11);
                        xlsSheetEn.MergedCells.Add(mCell);
                        /////En

                        for (int row = rParking + sumRow; row <= rParking + sumRow + dt.Rows.Count; row++)
                        {
                            for (int col = 1; col <= 13; col++)
                            {
                                xlsSheet[row, col].Style = xlstStyle;
                                xlsSheetEn[row, col].Style = xlstStyle;
                            }
                        }

                        for (int col = 1; col <= 13; col++)
                        {
                            xlsSheet[rParking + 1 + j, col].Style = xlstStyleSum;
                            xlsSheetEn[rParking + 1 + j, col].Style = xlstStyleSum;
                        }
                        sumRow += dt.Rows.Count - 1;
                    }
                }

                ds = new DataSet();
                sql = "SELECT id";
                sql += " ,YearMonth,BuildingId,CustomerId,RoomId,ExtraHour,VAT,OtherFee01,OtherFee02";
                sql += " ,PriceUSD,PriceVND,VatUSD,VatVND,SumUSD,SumVND,LastPriceUSD,LastPriceVND";
                sql += " ,RentArea,dbo.fnDateTime(FromWD) BeginDate,dbo.fnDateTime(EndWD) EndDate,ExtratimeType";
                sql += " FROM PaymentExtraTimeMonth";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth in (" + lsYearmonth + ")";

                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    line = rExtra - 3 + j;
                    //Phi dien
                    XLCellRange mCell = new XLCellRange(line, line + 2, 1, 3);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line + 2, 4, 4);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 6, 7);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 6, 7);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 8, 9);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 8, 9);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 10, 11);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 10, 11);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);

                    /////En
                    mCell = new XLCellRange(line, line + 2, 1, 3);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line + 2, 4, 4);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 6, 7);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 6, 7);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 8, 9);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 8, 9);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 10, 11);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 10, 11);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 12, 13);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 12, 13);
                    xlsSheetEn.MergedCells.Add(mCell);
                    /////En
                    if (ds != null)
                    {
                        int count = 0;
                        DataTable dt = ds.Tables[0];

                        foreach (DataRow row in dt.Rows)
                        {
                            if (count >= 1)
                            {
                                xlsSheet.Rows.Insert(rExtra + 1 + j);
                                xlsSheetEn.Rows.Insert(rExtra + 1 + j);
                                j++;
                            }
                            count++;
                            int tmp = rExtra + j;

                            string ExtraHour = Func.ParseString(row["ExtraHour"]);
                            string BeginDate = Func.ParseString(row["BeginDate"]);
                            string EndDate = Func.ParseString(row["EndDate"]);

                            string ExtratimeType = Func.ParseString(row["ExtratimeType"]);

                            xlsSheet[tmp, 1].Value = BeginDate + "~" + EndDate;
                            xlsSheet[tmp, 5].Value = ExtraHour;

                            xlsSheet[tmp, 4].Value = "Diện tích";
                            if ("0".Equals(ExtratimeType))
                            {
                                xlsSheet[tmp, 4].Value = "m2*h";
                            }
                            xlsSheet[tmp, 6].Value = row["PriceUSD"];
                            xlsSheet[tmp, 7].Value = row["PriceVND"];

                            xlsSheet[tmp, 8].Value = row["SumUSD"];
                            xlsSheet[tmp, 9].Value = row["SumVND"];

                            xlsSheet[tmp, 10].Value = row["VatUSD"];
                            xlsSheet[tmp, 11].Value = row["VatVND"];

                            xlsSheet[tmp, 12].Value = row["LastPriceUSD"];
                            xlsSheet[tmp, 13].Value = row["LastPriceVND"];

                            LastSumPriceVND[3] += Convert.ToDecimal(row["LastPriceVND"]);
                            LastSumPriceUSD[3] += Convert.ToDecimal(row["LastPriceUSD"]);

                            XLCellRange mrCell = new XLCellRange(tmp, tmp, 1, 3);
                            xlsSheet.MergedCells.Add(mrCell);
                            //////En
                            xlsSheetEn[tmp, 1].Value = BeginDate + "~" + EndDate;
                            xlsSheetEn[tmp, 5].Value = ExtraHour;

                            xlsSheetEn[tmp, 4].Value = "Di?n tích";
                            if ("0".Equals(ExtratimeType))
                            {
                                xlsSheetEn[tmp, 4].Value = "m2*h";
                            }
                            xlsSheetEn[tmp, 6].Value = row["PriceUSD"];
                            xlsSheetEn[tmp, 7].Value = row["PriceVND"];

                            xlsSheetEn[tmp, 8].Value = row["SumUSD"];
                            xlsSheetEn[tmp, 9].Value = row["SumVND"];

                            xlsSheetEn[tmp, 10].Value = row["VatUSD"];
                            xlsSheetEn[tmp, 11].Value = row["VatVND"];

                            xlsSheetEn[tmp, 12].Value = row["LastPriceUSD"];
                            xlsSheetEn[tmp, 13].Value = row["LastPriceVND"];

                            LastSumPriceVND[3] += Convert.ToDecimal(row["LastPriceVND"]);
                            LastSumPriceUSD[3] += Convert.ToDecimal(row["LastPriceUSD"]);

                            mrCell = new XLCellRange(tmp, tmp, 1, 3);
                            xlsSheetEn.MergedCells.Add(mrCell);
                            //////En

                            for (int col = 1; col <= 13; col++)
                            {
                                xlsSheet[tmp, col].Style = xlstStyle;
                                xlsSheetEn[tmp, col].Style = xlstStyle;
                            }

                        }
                        mCell = new XLCellRange(rExtra + 1 + j, rExtra + 1 + j, 1, 11);
                        xlsSheet.MergedCells.Add(mCell);
                        xlsSheetEn.MergedCells.Add(mCell);

                        xlsSheet[rExtra + 1 + j, 12].Value = LastSumPriceUSD[3];
                        xlsSheet[rExtra + 1 + j, 13].Value = LastSumPriceVND[3];

                        xlsSheetEn[rExtra + 1 + j, 12].Value = LastSumPriceUSD[3];
                        xlsSheetEn[rExtra + 1 + j, 13].Value = LastSumPriceVND[3];

                        for (int row = rExtra + sumRow; row <= rExtra + sumRow + dt.Rows.Count; row++)
                        {
                            for (int col = 1; col <= 13; col++)
                            {
                                xlsSheet[row, col].Style = xlstStyle;
                                xlsSheetEn[row, col].Style = xlstStyle;
                            }
                        }

                        for (int col = 1; col <= 12; col++)
                        {
                            xlsSheet[rExtra + 1 + j, col].Style = xlstStyleSum;
                            xlsSheetEn[rExtra + 1 + j, col].Style = xlstStyleSum;
                        }
                        sumRow += dt.Rows.Count - 1;
                    }
                }

                ds = new DataSet();
                //Dien
                //Xuất ra toàn bộ nội dung theo Trang
                sql = " SELECT dbo.fnDateTime(A.DateFrom) DateFrom, dbo.fnDateTime(A.DateTo) DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.OtherFee02, B.Mount, B.PriceVND, B.PriceUSD, B.SumVND, B.SumUSD, ";
                sql += "        B.VatVND, B.VatUSD, B.LastPriceVND, B.LastPriceUSD, B.Name, B.WaterPricePercent,B.ElecPricePercent ";
                sql += " FROM   PaymentElecWater AS A INNER JOIN ";
                sql += "        PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId";
                sql += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfWaterId = 0  and A.YearMonth in (" + lsYearmonth + ")";
                sql += " Order by A.DateFrom, B.FromIndex";

                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    line = rElec - 3 + j;
                    //Phi dien
                    XLCellRange mCell = new XLCellRange(line, line + 2, 1, 1);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line + 2, 2, 2);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 3, 3);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 4, 4);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 5, 5);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 7, 7);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 8, 8);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 9, 9);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 10, 10);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 11, 11);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);
                    /////En
                    mCell = new XLCellRange(line, line + 2, 1, 1);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line + 2, 2, 2);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 3, 3);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 4, 4);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 5, 5);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 7, 7);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 8, 8);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 9, 9);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 10, 10);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 11, 11);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 12, 13);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 12, 13);
                    xlsSheetEn.MergedCells.Add(mCell);
                    /////En

                    for (int col = 1; col < 13; col++)
                    {
                        xlsSheet[line, col].Style = xlstStyleH;
                        xlsSheet[line + 1, col].Style = xlstStyleH;
                        xlsSheet[line + 2, col].Style = xlstStyleH;

                        xlsSheetEn[line, col].Style = xlstStyleH;
                        xlsSheetEn[line + 1, col].Style = xlstStyleH;
                        xlsSheetEn[line + 2, col].Style = xlstStyleH;
                    }

                    if (ds != null)
                    {
                        int count = 0;
                        DataTable dt = ds.Tables[0];
                        if (dt.Rows.Count > 0)
                        {
                            foreach (DataRow row in dt.Rows)
                            {
                                if (count >= 1)
                                {
                                    xlsSheet.Rows.Insert(rElec + 1 + j);
                                    xlsSheetEn.Rows.Insert(rElec + 1 + j);
                                    j++;

                                }
                                count++;
                                int tmp = rElec + j;

                                string DateFrom = Func.ParseString(row["DateFrom"]);
                                string DateTo = Func.ParseString(row["DateTo"]);

                                string FromIndex = Func.ParseString(row["FromIndex"]);
                                string ToIndex = Func.ParseString(row["ToIndex"]);
                                string OtherFee01 = Func.ParseString(row["OtherFee01"]);
                                string OtherFee02 = Func.ParseString(row["OtherFee02"]);
                                string Mount = Func.ParseString(row["Mount"]);
                                string ElecPricePercent = Func.ParseString(row["ElecPricePercent"]);

                                xlsSheet[tmp, 1].Value = DateFrom;
                                xlsSheet[tmp, 2].Value = DateTo;
                                xlsSheet[tmp, 3].Value = FromIndex;
                                xlsSheet[tmp, 4].Value = ToIndex;
                                xlsSheet[tmp, 5].Value = OtherFee01;
                                xlsSheet[tmp, 6].Value = Mount;
                                xlsSheet[tmp, 7].Value = row["PriceVND"];
                                xlsSheet[tmp, 8].Value = row["VatVND"];

                                xlsSheet[tmp, 9].Value = row["SumVND"];
                                xlsSheet[tmp, 10].Value = row["OtherFee02"];
                                xlsSheet[tmp, 11].Value = row["ElecPricePercent"];
                                xlsSheet[tmp, 12].Value = row["LastPriceVND"];

                                mCell = new XLCellRange(tmp, tmp, 12, 13);
                                xlsSheet.MergedCells.Add(mCell);

                                /////En
                                xlsSheetEn[tmp, 1].Value = DateFrom;
                                xlsSheetEn[tmp, 2].Value = DateTo;
                                xlsSheetEn[tmp, 3].Value = FromIndex;
                                xlsSheetEn[tmp, 4].Value = ToIndex;
                                xlsSheetEn[tmp, 5].Value = OtherFee01;
                                xlsSheetEn[tmp, 6].Value = Mount;
                                xlsSheetEn[tmp, 7].Value = row["PriceVND"];
                                xlsSheetEn[tmp, 8].Value = row["VatVND"];

                                xlsSheetEn[tmp, 9].Value = row["SumVND"];
                                xlsSheetEn[tmp, 10].Value = row["OtherFee02"];
                                xlsSheetEn[tmp, 11].Value = row["ElecPricePercent"];
                                xlsSheetEn[tmp, 12].Value = row["LastPriceVND"];

                                mCell = new XLCellRange(tmp, tmp, 12, 13);
                                xlsSheetEn.MergedCells.Add(mCell);
                                /////En
                                for (int col = 1; col <= 12; col++)
                                {
                                    xlsSheet[tmp, col].Style = xlstStyle;
                                    xlsSheetEn[tmp, col].Style = xlstStyle;
                                }
                                LastSumPriceVND[4] += Convert.ToDecimal(row["LastPriceVND"]);
                                LastSumPriceUSD[4] += Convert.ToDecimal(row["LastPriceUSD"]);
                            }
                            xlsSheet[rElec + 1 + j, 12].Value = LastSumPriceVND[4];
                            mCell = new XLCellRange(rElec + 1 + j, rElec + 1 + j, 1, 11);
                            xlsSheet.MergedCells.Add(mCell);

                            mCell = new XLCellRange(rElec + 1 + j, rElec + 1 + j, 12, 13);
                            xlsSheet.MergedCells.Add(mCell);

                            xlsSheetEn[rElec + 1 + j, 12].Value = LastSumPriceVND[4];
                            mCell = new XLCellRange(rElec + 1 + j, rElec + 1 + j, 1, 11);
                            xlsSheetEn.MergedCells.Add(mCell);

                            mCell = new XLCellRange(rElec + 1 + j, rElec + 1 + j, 12, 13);
                            xlsSheetEn.MergedCells.Add(mCell);

                            for (int col = 1; col <= 13; col++)
                            {
                                xlsSheet[rElec + 1 + j, col].Style = xlstStyleSum;
                                xlsSheetEn[rElec + 1 + j, col].Style = xlstStyleSum;
                            }
                            sumRow += dt.Rows.Count - 1;
                        }
                    }
                }

                ds = new DataSet();
                //Nuoc
                //Xuất ra toàn bộ nội dung theo Trang
                sql = " SELECT dbo.fnDateTime(A.DateFrom) DateFrom, dbo.fnDateTime(A.DateTo) DateTo, A.Vat, B.id, B.UsedElecWaterId, B.FromIndex, B.ToIndex, B.OtherFee01, B.OtherFee02, B.Mount, B.PriceVND, B.PriceUSD, B.SumVND, B.SumUSD, ";
                sql += "        B.VatVND, B.VatUSD, B.LastPriceVND, B.LastPriceUSD, B.Name, B.WaterPricePercent,B.ElecPricePercent  ";
                sql += " FROM   PaymentElecWater AS A INNER JOIN ";
                sql += "        PaymentElecWaterDetail AS B ON A.UsedElecWaterId = B.UsedElecWaterId";
                sql += " WHERE A.BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and A.CustomerId = '" + hidId.Value + "' and TarrifsOfElecId = 0 and A.YearMonth in (" + lsYearmonth + ")";
                sql += " Order by A.DateFrom, B.FromIndex";

                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    line = rWater - 3 + j;
                    //Phi dien
                    XLCellRange mCell = new XLCellRange(line, line + 2, 1, 1);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line + 2, 2, 2);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 3, 3);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 4, 4);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 6, 6);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 7, 7);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 8, 8);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 9, 9);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 10, 10);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 11, 11);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);

                    /////En
                    mCell = new XLCellRange(line, line + 2, 1, 1);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line + 2, 2, 2);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 3, 3);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 4, 4);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 6, 6);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 7, 7);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 8, 8);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 9, 9);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 10, 10);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 11, 11);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 12, 13);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 12, 13);
                    xlsSheetEn.MergedCells.Add(mCell);
                    /////En

                    for (int col = 1; col < 13; col++)
                    {
                        xlsSheet[line, col].Style = xlstStyleH;
                        xlsSheet[line + 1, col].Style = xlstStyleH;
                        xlsSheet[line + 2, col].Style = xlstStyleH;

                        xlsSheetEn[line, col].Style = xlstStyleH;
                        xlsSheetEn[line + 1, col].Style = xlstStyleH;
                        xlsSheetEn[line + 2, col].Style = xlstStyleH;
                    }

                    if (ds != null)
                    {
                        int count = 0;
                        DataTable dt = ds.Tables[0];
                        if (dt.Rows.Count > 0)
                        {
                            foreach (DataRow row in dt.Rows)
                            {
                                if (count >= 1)
                                {
                                    xlsSheet.Rows.Insert(rWater + 1 + j);
                                    xlsSheetEn.Rows.Insert(rWater + 1 + j);
                                    j++;
                                }
                                count++;
                                int tmp = rWater + j;

                                string DateFrom = Func.ParseString(row["DateFrom"]);
                                string DateTo = Func.ParseString(row["DateTo"]);

                                string FromIndex = Func.ParseString(row["FromIndex"]);
                                string ToIndex = Func.ParseString(row["ToIndex"]);
                                string OtherFee01 = Func.ParseString(row["OtherFee01"]);
                                string OtherFee02 = Func.ParseString(row["OtherFee02"]);
                                string Mount = Func.ParseString(row["Mount"]);

                                xlsSheet[tmp, 1].Value = DateFrom;
                                xlsSheet[tmp, 2].Value = DateTo;
                                xlsSheet[tmp, 3].Value = FromIndex;
                                xlsSheet[tmp, 4].Value = ToIndex;
                                xlsSheet[tmp, 5].Value = Mount;
                                xlsSheet[tmp, 6].Value = row["PriceVND"];
                                xlsSheet[tmp, 7].Value = row["OtherFee01"];
                                xlsSheet[tmp, 8].Value = row["VatVND"];

                                xlsSheet[tmp, 9].Value = row["SumVND"];
                                xlsSheet[tmp, 10].Value = row["OtherFee02"];
                                xlsSheet[tmp, 11].Value = row["WaterPricePercent"];
                                xlsSheet[tmp, 12].Value = row["LastPriceVND"];

                                /////En
                                xlsSheetEn[tmp, 1].Value = DateFrom;
                                xlsSheetEn[tmp, 2].Value = DateTo;
                                xlsSheetEn[tmp, 3].Value = FromIndex;
                                xlsSheetEn[tmp, 4].Value = ToIndex;
                                xlsSheetEn[tmp, 5].Value = Mount;
                                xlsSheetEn[tmp, 6].Value = row["PriceVND"];
                                xlsSheetEn[tmp, 7].Value = row["OtherFee01"];
                                xlsSheetEn[tmp, 8].Value = row["VatVND"];

                                xlsSheetEn[tmp, 9].Value = row["SumVND"];
                                xlsSheetEn[tmp, 10].Value = row["OtherFee02"];
                                xlsSheetEn[tmp, 11].Value = row["WaterPricePercent"];
                                xlsSheetEn[tmp, 12].Value = row["LastPriceVND"];

                                /////En
                                for (int col = 1; col <= 12; col++)
                                {
                                    xlsSheet[tmp, col].Style = xlstStyle;
                                    xlsSheetEn[tmp, col].Style = xlstStyle;
                                }
                                LastSumPriceVND[5] += Convert.ToDecimal(row["LastPriceVND"]);
                                LastSumPriceUSD[5] += Convert.ToDecimal(row["LastPriceUSD"]);

                                mCell = new XLCellRange(tmp, tmp, 12, 13);
                                xlsSheet.MergedCells.Add(mCell);
                                xlsSheetEn.MergedCells.Add(mCell);
                            }
                            xlsSheet[rWater + 1 + j, 12].Value = LastSumPriceVND[5];
                            xlsSheetEn[rWater + 1 + j, 12].Value = LastSumPriceVND[5];
                            mCell = new XLCellRange(rWater + 1 + j, rWater + 1 + j, 1, 11);
                            xlsSheet.MergedCells.Add(mCell);
                            xlsSheetEn.MergedCells.Add(mCell);

                            mCell = new XLCellRange(rWater + 1 + j, rWater + 1 + j, 12, 13);
                            xlsSheet.MergedCells.Add(mCell);
                            xlsSheetEn.MergedCells.Add(mCell);

                            for (int col = 1; col <= 13; col++)
                            {
                                xlsSheet[rWater + 1 + j, col].Style = xlstStyleSum;
                                xlsSheetEn[rWater + 1 + j, col].Style = xlstStyleSum;
                            }
                            sumRow += dt.Rows.Count - 1;
                        }
                    }
                }

                //Service
                ds = new DataSet();

                sql = string.Empty;
                sql = " SELECT Service,dbo.fnDateTime(ServiceDateFrom) ServiceDateFrom,dbo.fnDateTime(ServiceDateTo) ServiceDateTo,PriceVND,PriceUSD,VatUSD,VatVND,Mount,Unit,SumVND,SumUSD,LastPriceVND,LastPriceUSD ";
                sql += " FROM   PaymentService";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth in (" + lsYearmonth + ")";
                sql += " Order By ServiceDate ";

                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    line = rService - 3 + j;
                    //Phi khác
                    XLCellRange mCell = new XLCellRange(line, line + 2, 1, 1);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line + 2, 2, 2);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line + 2, 3, 3);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line + 2, 4, 4);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 5, 5);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 6, 7);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 6, 7);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 8, 9);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 8, 9);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 10, 11);
                    xlsSheet.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 10, 11);
                    xlsSheet.MergedCells.Add(mCell);

                    /////En
                    mCell = new XLCellRange(line, line + 2, 1, 1);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line + 2, 2, 2);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line + 2, 3, 3);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line + 2, 4, 4);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 2, 5, 5);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 6, 7);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 6, 7);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 8, 9);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 8, 9);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line, line, 10, 11);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 10, 11);
                    xlsSheetEn.MergedCells.Add(mCell);
                    /////En
                    for (int col = 1; col < 13; col++)
                    {
                        xlsSheet[line, col].Style = xlstStyleH;
                        xlsSheet[line + 1, col].Style = xlstStyleH;
                        xlsSheet[line + 2, col].Style = xlstStyleH;

                        xlsSheetEn[line, col].Style = xlstStyleH;
                        xlsSheetEn[line + 1, col].Style = xlstStyleH;
                        xlsSheetEn[line + 2, col].Style = xlstStyleH;
                    }
                    mCell = new XLCellRange(line, line, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);
                    xlsSheetEn.MergedCells.Add(mCell);

                    mCell = new XLCellRange(line + 1, line + 1, 12, 13);
                    xlsSheet.MergedCells.Add(mCell);
                    xlsSheetEn.MergedCells.Add(mCell);

                    if (ds != null)
                    {
                        int count = 0;
                        DataTable dt = ds.Tables[0];

                        if (dt.Rows.Count > 0)
                        {

                            foreach (DataRow row in dt.Rows)
                            {
                                if (count >= 1)
                                {
                                    xlsSheet.Rows.Insert(rService + 1 + j);
                                    xlsSheetEn.Rows.Insert(rService + 1 + j);
                                    j++;
                                }
                                count++;
                                int tmp = rService + j;

                                string Service = Func.ParseString(row["Service"]);
                                string ServiceDateFrom = Func.ParseString(row["ServiceDateFrom"]);
                                string ServiceDateTo = Func.ParseString(row["ServiceDateTo"]);

                                string Mount = Func.ParseString(row["Mount"]);

                                xlsSheet[tmp, 1].Value = Service;
                                xlsSheet[tmp, 2].Value = Func.ParseString(row["Unit"]);
                                xlsSheet[tmp, 3].Value = ServiceDateFrom;
                                xlsSheet[tmp, 4].Value = ServiceDateTo;
                                xlsSheet[tmp, 5].Value = Mount;

                                xlsSheet[tmp, 6].Value = row["PriceUSD"];
                                xlsSheet[tmp, 7].Value = row["PriceVND"];

                                xlsSheet[tmp, 8].Value = row["SumUSD"];
                                xlsSheet[tmp, 9].Value = row["SumVND"];

                                xlsSheet[tmp, 10].Value = row["VatUSD"];
                                xlsSheet[tmp, 11].Value = row["VatVND"];

                                xlsSheet[tmp, 12].Value = row["LastPriceUSD"];
                                xlsSheet[tmp, 13].Value = row["LastPriceVND"];

                                /////En
                                xlsSheetEn[tmp, 1].Value = Service;
                                xlsSheetEn[tmp, 2].Value = Func.ParseString(row["Unit"]);
                                xlsSheetEn[tmp, 3].Value = ServiceDateFrom;
                                xlsSheetEn[tmp, 4].Value = ServiceDateTo;
                                xlsSheetEn[tmp, 5].Value = Mount;

                                xlsSheetEn[tmp, 6].Value = row["PriceUSD"];
                                xlsSheetEn[tmp, 7].Value = row["PriceVND"];

                                xlsSheetEn[tmp, 8].Value = row["SumUSD"];
                                xlsSheetEn[tmp, 9].Value = row["SumVND"];

                                xlsSheetEn[tmp, 10].Value = row["VatUSD"];
                                xlsSheetEn[tmp, 11].Value = row["VatVND"];

                                xlsSheetEn[tmp, 12].Value = row["LastPriceUSD"];
                                xlsSheetEn[tmp, 13].Value = row["LastPriceVND"];
                                /////En

                                for (int col = 1; col <= 13; col++)
                                {
                                    xlsSheet[tmp, col].Style = xlstStyle;
                                    xlsSheetEn[tmp, col].Style = xlstStyle;
                                }
                                LastSumPriceVND[6] += Convert.ToDecimal(row["LastPriceVND"]);
                                LastSumPriceUSD[6] += Convert.ToDecimal(row["LastPriceUSD"]);
                            }
                            xlsSheet[rService + 1 + j, 12].Value = LastSumPriceUSD[6];
                            xlsSheet[rService + 1 + j, 13].Value = LastSumPriceVND[6];

                            xlsSheetEn[rService + 1 + j, 12].Value = LastSumPriceUSD[6];
                            xlsSheetEn[rService + 1 + j, 13].Value = LastSumPriceVND[6];

                            mCell = new XLCellRange(rService + 1 + j, rService + 1 + j, 1, 11);
                            xlsSheet.MergedCells.Add(mCell);
                            xlsSheetEn.MergedCells.Add(mCell);

                            for (int col = 1; col <= 13; col++)
                            {
                                xlsSheet[rService + 1 + j, col].Style = xlstStyleSum;
                                xlsSheetEn[rService + 1 + j, col].Style = xlstStyleSum;
                            }
                            sumRow += dt.Rows.Count - 1;
                        }
                    }
                }

                //Paid
                sql = "Select  *";
                sql += " From    PaymentBillDetail";
                sql += " Where   BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth in (" + lsYearmonth + ")";
                string strYearMonth = "";
                int lineTmp = rPaid - 2 + j;

                //Paid
                XLCellRange mCellTmp = new XLCellRange(lineTmp, lineTmp + 1, 1, 1);
                xlsSheet.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 2, 3);
                xlsSheet.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 4, 5);
                xlsSheet.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 6, 7);
                xlsSheet.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 8, 9);
                xlsSheet.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 12, 13);
                xlsSheet.MergedCells.Add(mCellTmp);

                /////En
                mCellTmp = new XLCellRange(lineTmp, lineTmp + 1, 1, 1);
                xlsSheetEn.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 2, 3);
                xlsSheetEn.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 4, 5);
                xlsSheetEn.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 6, 7);
                xlsSheetEn.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 8, 9);
                xlsSheetEn.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 12, 13);
                xlsSheetEn.MergedCells.Add(mCellTmp);
                /////En
                Hashtable rowNo = new Hashtable();
                decimal[] PaidSumVND = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 };
                decimal[] PaidSumUSD = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 };

                DataTable dtPaid = DbHelper.GetDataTable(sql);
                for (int i = 0; i < dtPaid.Rows.Count; i++)
                {
                    string PaymentType = Func.ParseString(dtPaid.Rows[i]["PaymentType"]);
                    string MoneyUSD = Func.ParseString(dtPaid.Rows[i]["MoneyUSD"]);
                    string MoneyVND = Func.ParseString(dtPaid.Rows[i]["MoneyVND"]);
                    string PaidUSD = Func.ParseString(dtPaid.Rows[i]["PaidUSD"]);
                    string PaidVND = Func.ParseString(dtPaid.Rows[i]["PaidVND"]);
                    string ExchangeType = Func.ParseString(dtPaid.Rows[i]["ExchangeType"]);
                    string UsdExchange = Func.ParseString(dtPaid.Rows[i]["UsdExchange"]);
                    string YearMonth = Func.ParseString(dtPaid.Rows[i]["YearMonth"]);

                    if (!rowNo.Contains(YearMonth))
                    {
                        if (rowNo.Count != 0)
                        {
                            xlsSheet.Rows.Insert(rPaid + j + 1);
                            xlsSheetEn.Rows.Insert(rPaid + j + 1);
                            j++;
                        }
                        rowNo.Add(YearMonth, j);
                    }
                    int m = Func.ParseInt(rowNo[YearMonth]);
                    strYearMonth = YearMonth;
                    decimal tmpUSD = Convert.ToDecimal(MoneyUSD) - Convert.ToDecimal(PaidUSD);
                    decimal tmpVND = Convert.ToDecimal(MoneyVND) - Convert.ToDecimal(PaidVND);

                    PaidPriceUSD += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]);
                    PaidPriceVND += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]);

                    xlsSheet[rPaid + m, 1].Value = YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4);
                    xlsSheetEn[rPaid + m, 1].Value = YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4);
                    switch (PaymentType)
                    {
                        case "1":
                            //Rent
                            xlsSheet[rPaid + m, 2].Value = dtPaid.Rows[i]["PaidUSD"];
                            xlsSheet[rPaid + m, 3].Value = dtPaid.Rows[i]["PaidVND"];

                            xlsSheetEn[rPaid + m, 2].Value = dtPaid.Rows[i]["PaidUSD"];
                            xlsSheetEn[rPaid + m, 3].Value = dtPaid.Rows[i]["PaidVND"];

                            PaidSumUSD[0] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]);
                            PaidSumVND[0] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]);

                            break;
                        case "2":
                            //Manager
                            xlsSheet[rPaid + m, 4].Value = dtPaid.Rows[i]["PaidUSD"];
                            xlsSheet[rPaid + m, 5].Value = dtPaid.Rows[i]["PaidVND"];

                            xlsSheetEn[rPaid + m, 4].Value = dtPaid.Rows[i]["PaidUSD"];
                            xlsSheetEn[rPaid + m, 5].Value = dtPaid.Rows[i]["PaidVND"];

                            PaidSumUSD[1] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]);
                            PaidSumVND[1] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]);

                            break;
                        case "3":
                            //Parking
                            xlsSheet[rPaid + m, 6].Value = dtPaid.Rows[i]["PaidUSD"];
                            xlsSheet[rPaid + m, 7].Value = dtPaid.Rows[i]["PaidVND"];

                            xlsSheetEn[rPaid + m, 6].Value = dtPaid.Rows[i]["PaidUSD"];
                            xlsSheetEn[rPaid + m, 7].Value = dtPaid.Rows[i]["PaidVND"];

                            PaidSumUSD[2] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]);
                            PaidSumVND[2] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]);
                            break;
                        case "4":
                            //Extra
                            xlsSheet[rPaid + m, 8].Value = dtPaid.Rows[i]["PaidUSD"];
                            xlsSheet[rPaid + m, 9].Value = dtPaid.Rows[i]["PaidVND"];

                            xlsSheetEn[rPaid + m, 8].Value = dtPaid.Rows[i]["PaidUSD"];
                            xlsSheetEn[rPaid + m, 9].Value = dtPaid.Rows[i]["PaidVND"];

                            PaidSumUSD[3] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]);
                            PaidSumVND[3] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]);
                            break;
                        case "5":
                            xlsSheet[rPaid + m, 10].Value = dtPaid.Rows[i]["PaidVND"];
                            xlsSheetEn[rPaid + m, 10].Value = dtPaid.Rows[i]["PaidVND"];

                            PaidSumUSD[4] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]);
                            PaidSumVND[4] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]);
                            break;
                        case "6":
                            xlsSheet[rPaid + m, 11].Value = dtPaid.Rows[i]["PaidVND"];
                            xlsSheetEn[rPaid + m, 11].Value = dtPaid.Rows[i]["PaidVND"];

                            PaidSumUSD[5] += Convert.ToDecimal(dtPaid.Rows[i]["PaidUSD"]);
                            PaidSumVND[5] += Convert.ToDecimal(dtPaid.Rows[i]["PaidVND"]);
                            break;
                        case "7":
                            xlsSheet[rPaid + m, 12].Value = dtPaid.Rows[i]["PaidUSD"];
                            xlsSheet[rPaid + m, 13].Value = dtPaid.Rows[i]["PaidVND"];

                            xlsSheetEn[rPaid + m, 12].Value = dtPaid.Rows[i]["PaidUSD"];
                            xlsSheetEn[rPaid + m, 13].Value = dtPaid.Rows[i]["PaidVND"];
                            break;
                        default:
                            break;
                    }
                    for (int row = rPaid + m; row <= rPaid + 1 + j; row++)
                    {
                        for (int col = 1; col <= 13; col++)
                        {
                            xlsSheet[row, col].Style = xlstStyle;
                        }
                    }
                }
                lineTmp = rPaid - 2 + j;

                xlsSheet[lineTmp + 3, 2].Value = PaidSumUSD[0];
                xlsSheet[lineTmp + 3, 3].Value = PaidSumVND[0];
                xlsSheet[lineTmp + 3, 4].Value = PaidSumUSD[1];
                xlsSheet[lineTmp + 3, 5].Value = PaidSumVND[1];
                xlsSheet[lineTmp + 3, 6].Value = PaidSumUSD[2];
                xlsSheet[lineTmp + 3, 7].Value = PaidSumVND[2];
                xlsSheet[lineTmp + 3, 8].Value = PaidSumUSD[3];
                xlsSheet[lineTmp + 3, 9].Value = PaidSumVND[3];
                xlsSheet[lineTmp + 3, 10].Value = PaidSumVND[4];
                xlsSheet[lineTmp + 3, 11].Value = PaidSumVND[5];
                xlsSheet[lineTmp + 3, 12].Value = PaidSumUSD[6];
                xlsSheet[lineTmp + 3, 13].Value = PaidSumVND[6];

                /////En
                xlsSheetEn[lineTmp + 3, 2].Value = PaidSumUSD[0];
                xlsSheetEn[lineTmp + 3, 3].Value = PaidSumVND[0];
                xlsSheetEn[lineTmp + 3, 4].Value = PaidSumUSD[1];
                xlsSheetEn[lineTmp + 3, 5].Value = PaidSumVND[1];
                xlsSheetEn[lineTmp + 3, 6].Value = PaidSumUSD[2];
                xlsSheetEn[lineTmp + 3, 7].Value = PaidSumVND[2];
                xlsSheetEn[lineTmp + 3, 8].Value = PaidSumUSD[3];
                xlsSheetEn[lineTmp + 3, 9].Value = PaidSumVND[3];
                xlsSheetEn[lineTmp + 3, 10].Value = PaidSumVND[4];
                xlsSheetEn[lineTmp + 3, 11].Value = PaidSumVND[5];
                xlsSheetEn[lineTmp + 3, 12].Value = PaidSumUSD[6];
                xlsSheetEn[lineTmp + 3, 13].Value = PaidSumVND[6];
                /////En

                for (int col = 1; col <= 13; col++)
                {
                    xlsSheet[lineTmp + 3, col].Style = xlstStyleSum;
                    xlsSheetEn[lineTmp + 3, col].Style = xlstStyleSum;
                }

                ///////////////DEPT
                sql = "  Select *";
                sql += " From   v_DeptBill";
                sql += " Where  BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and CustomerId = '" + hidId.Value + "' and YearMonth not in (" + lsYearmonth + ")";
                sql += " And    (DeptUsd <> 0 or DeptVnd <> 0)";
                strYearMonth = "";
                lineTmp = rDept - 2 + j;

                //Paid
                mCellTmp = new XLCellRange(lineTmp, lineTmp + 1, 1, 1);
                xlsSheet.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 2, 3);
                xlsSheet.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 4, 5);
                xlsSheet.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 6, 7);
                xlsSheet.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 8, 9);
                xlsSheet.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 12, 13);
                xlsSheet.MergedCells.Add(mCellTmp);

                //////En
                mCellTmp = new XLCellRange(lineTmp, lineTmp + 1, 1, 1);
                xlsSheetEn.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 2, 3);
                xlsSheetEn.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 4, 5);
                xlsSheetEn.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 6, 7);
                xlsSheetEn.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 8, 9);
                xlsSheetEn.MergedCells.Add(mCellTmp);

                mCellTmp = new XLCellRange(lineTmp, lineTmp, 12, 13);
                xlsSheetEn.MergedCells.Add(mCellTmp);
                //////En
                rowNo = new Hashtable();
                decimal DeptPriceVND = 0;
                decimal DeptPriceUSD = 0;

                decimal[] DeptSumVND = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 };
                decimal[] DeptSumUSD = new decimal[7] { 0, 0, 0, 0, 0, 0, 0 };

                DataTable dtDept = DbHelper.GetDataTable(sql);
                for (int i = 0; i < dtDept.Rows.Count; i++)
                {
                    string PaymentType = Func.ParseString(dtDept.Rows[i]["PaymentType"]);
                    string DeptUSD = Func.ParseString(dtDept.Rows[i]["DeptUSD"]);
                    string DeptVND = Func.ParseString(dtDept.Rows[i]["DeptVND"]);
                    string YearMonth = Func.ParseString(dtDept.Rows[i]["YearMonth"]);

                    if (!rowNo.Contains(YearMonth))
                    {
                        if (rowNo.Count != 0)
                        {
                            xlsSheet.Rows.Insert(rDept + j + 1);
                            xlsSheetEn.Rows.Insert(rDept + j + 1);
                            j++;
                        }
                        rowNo.Add(YearMonth, j);
                    }
                    int m = Func.ParseInt(rowNo[YearMonth]);
                    strYearMonth = YearMonth;

                    DeptPriceUSD += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]);
                    DeptPriceVND += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);

                    xlsSheet[rDept + m, 1].Value = YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4);
                    xlsSheetEn[rDept + m, 1].Value = YearMonth.Substring(4, 2) + "/" + YearMonth.Substring(0, 4);

                    xlsSheetEn[rDept + m, 2].Value = 0;
                    xlsSheetEn[rDept + m, 3].Value = 0;
                    xlsSheetEn[rDept + m, 4].Value = 0;
                    xlsSheetEn[rDept + m, 5].Value = 0;
                    xlsSheetEn[rDept + m, 6].Value = 0;
                    xlsSheetEn[rDept + m, 7].Value = 0;
                    xlsSheetEn[rDept + m, 8].Value = 0;
                    xlsSheetEn[rDept + m, 9].Value = 0;
                    xlsSheetEn[rDept + m, 10].Value = 0;
                    xlsSheetEn[rDept + m, 11].Value = 0;
                    xlsSheetEn[rDept + m, 12].Value = 0;
                    xlsSheetEn[rDept + m, 13].Value = 0;

                    xlsSheet[rDept + m, 2].Value = 0;
                    xlsSheet[rDept + m, 3].Value = 0;
                    xlsSheet[rDept + m, 4].Value = 0;
                    xlsSheet[rDept + m, 5].Value = 0;
                    xlsSheet[rDept + m, 6].Value = 0;
                    xlsSheet[rDept + m, 7].Value = 0;
                    xlsSheet[rDept + m, 8].Value = 0;
                    xlsSheet[rDept + m, 9].Value = 0;
                    xlsSheet[rDept + m, 10].Value = 0;
                    xlsSheet[rDept + m, 11].Value = 0;
                    xlsSheet[rDept + m, 12].Value = 0;
                    xlsSheet[rDept + m, 13].Value = 0;

                    switch (PaymentType)
                    {
                        case "1":
                            //Rent
                            xlsSheet[rDept + m, 2].Value = dtDept.Rows[i]["DeptUSD"];
                            xlsSheet[rDept + m, 3].Value = dtDept.Rows[i]["DeptVND"];

                            xlsSheetEn[rDept + m, 2].Value = dtDept.Rows[i]["DeptUSD"];
                            xlsSheetEn[rDept + m, 3].Value = dtDept.Rows[i]["DeptVND"];

                            DeptSumUSD[0] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]);
                            DeptSumVND[0] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);

                            break;
                        case "2":
                            //Manager
                            xlsSheet[rDept + m, 4].Value = dtDept.Rows[i]["DeptUSD"];
                            xlsSheet[rDept + m, 5].Value = dtDept.Rows[i]["DeptVND"];

                            xlsSheetEn[rDept + m, 4].Value = dtDept.Rows[i]["DeptUSD"];
                            xlsSheetEn[rDept + m, 5].Value = dtDept.Rows[i]["DeptVND"];

                            DeptSumUSD[1] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]);
                            DeptSumVND[1] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);

                            break;
                        case "3":
                            //Parking
                            xlsSheet[rDept + m, 6].Value = dtDept.Rows[i]["DeptUSD"];
                            xlsSheet[rDept + m, 7].Value = dtDept.Rows[i]["DeptVND"];

                            xlsSheetEn[rDept + m, 6].Value = dtDept.Rows[i]["DeptUSD"];
                            xlsSheetEn[rDept + m, 7].Value = dtDept.Rows[i]["DeptVND"];

                            DeptSumUSD[2] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]);
                            DeptSumVND[2] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);
                            break;
                        case "4":
                            //Extra
                            xlsSheet[rDept + m, 8].Value = dtDept.Rows[i]["DeptUSD"];
                            xlsSheet[rDept + m, 9].Value = dtDept.Rows[i]["DeptVND"];

                            xlsSheetEn[rDept + m, 8].Value = dtDept.Rows[i]["DeptUSD"];
                            xlsSheetEn[rDept + m, 9].Value = dtDept.Rows[i]["DeptVND"];

                            DeptSumUSD[3] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]);
                            DeptSumVND[3] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);
                            break;
                        case "5":
                            xlsSheet[rDept + m, 10].Value = dtDept.Rows[i]["DeptVND"];
                            xlsSheetEn[rDept + m, 10].Value = dtDept.Rows[i]["DeptVND"];

                            DeptSumUSD[4] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]);
                            DeptSumVND[4] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);
                            break;
                        case "6":
                            xlsSheet[rDept + m, 11].Value = dtDept.Rows[i]["DeptVND"];
                            xlsSheetEn[rDept + m, 11].Value = dtDept.Rows[i]["DeptVND"];

                            DeptSumUSD[5] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]);
                            DeptSumVND[5] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);
                            break;
                        case "7":
                            xlsSheet[rDept + m, 12].Value = dtDept.Rows[i]["DeptUSD"];
                            xlsSheet[rDept + m, 13].Value = dtDept.Rows[i]["DeptVND"];

                            xlsSheetEn[rDept + m, 12].Value = dtDept.Rows[i]["DeptUSD"];
                            xlsSheetEn[rDept + m, 13].Value = dtDept.Rows[i]["DeptVND"];

                            DeptSumUSD[6] += Convert.ToDecimal(dtDept.Rows[i]["DeptUSD"]);
                            DeptSumVND[6] += Convert.ToDecimal(dtDept.Rows[i]["DeptVND"]);
                            break;
                        default:
                            break;
                    }
                    for (int row = rDept + m; row <= rDept + 1 + j; row++)
                    {
                        for (int col = 1; col <= 13; col++)
                        {
                            xlsSheet[row, col].Style = xlstStyle;
                            xlsSheetEn[row, col].Style = xlstStyle;
                        }
                    }
                }
                lineTmp = rDept - 2 + j;

                xlsSheet[lineTmp + 3, 2].Value = DeptSumUSD[0];
                xlsSheet[lineTmp + 3, 3].Value = DeptSumVND[0];
                xlsSheet[lineTmp + 3, 4].Value = DeptSumUSD[1];
                xlsSheet[lineTmp + 3, 5].Value = DeptSumVND[1];
                xlsSheet[lineTmp + 3, 6].Value = DeptSumUSD[2];
                xlsSheet[lineTmp + 3, 7].Value = DeptSumVND[2];
                xlsSheet[lineTmp + 3, 8].Value = DeptSumUSD[3];
                xlsSheet[lineTmp + 3, 9].Value = DeptSumVND[3];
                xlsSheet[lineTmp + 3, 10].Value = DeptSumVND[4];
                xlsSheet[lineTmp + 3, 11].Value = DeptSumVND[5];
                xlsSheet[lineTmp + 3, 12].Value = DeptSumUSD[6];
                xlsSheet[lineTmp + 3, 13].Value = DeptSumVND[6];

                //////En
                xlsSheetEn[lineTmp + 3, 2].Value = DeptSumUSD[0];
                xlsSheetEn[lineTmp + 3, 3].Value = DeptSumVND[0];
                xlsSheetEn[lineTmp + 3, 4].Value = DeptSumUSD[1];
                xlsSheetEn[lineTmp + 3, 5].Value = DeptSumVND[1];
                xlsSheetEn[lineTmp + 3, 6].Value = DeptSumUSD[2];
                xlsSheetEn[lineTmp + 3, 7].Value = DeptSumVND[2];
                xlsSheetEn[lineTmp + 3, 8].Value = DeptSumUSD[3];
                xlsSheetEn[lineTmp + 3, 9].Value = DeptSumVND[3];
                xlsSheetEn[lineTmp + 3, 10].Value = DeptSumVND[4];
                xlsSheetEn[lineTmp + 3, 11].Value = DeptSumVND[5];
                xlsSheetEn[lineTmp + 3, 12].Value = DeptSumUSD[6];
                xlsSheetEn[lineTmp + 3, 13].Value = DeptSumVND[6];
                //////En
                for (int col = 1; col <= 13; col++)
                {
                    xlsSheet[lineTmp + 3, col].Style = xlstStyleSum;
                    xlsSheetEn[lineTmp + 3, col].Style = xlstStyleSum;
                }

                xlsSheet[lineTmp + 3, 1].Style = xlstStyleSum;
                xlsSheetEn[lineTmp + 3, 1].Style = xlstStyleSum;

                decimal AllSumVND = 0;
                decimal AllSumUSD = 0;
                for (int i = 0; i < 7; i++)
                {
                    AllSumVND += LastSumPriceVND[i];
                    AllSumUSD += LastSumPriceUSD[i];
                }

                AllSumVND -= PaidPriceVND;
                AllSumUSD -= PaidPriceUSD;

                AllSumVND += DeptPriceVND;
                AllSumUSD += DeptPriceUSD;

                xlsSheet[rSumVND + j, cSumVND].Value = Func.FormatNumber_New(AllSumUSD);
                xlsSheet[rSumVND + j, cSumVND].Value += "(USD)";
                xlsSheet[rSumVND + j, cSumVND + 1].Value = Func.FormatNumber_New(AllSumVND);
                xlsSheet[rSumVND + j, cSumVND + 1].Value += "(VND)";

                xlsSheetEn[rSumVND + j, cSumVND].Value = Func.FormatNumber_New(AllSumUSD);
                xlsSheetEn[rSumVND + j, cSumVND].Value += "(USD)";
                xlsSheetEn[rSumVND + j, cSumVND + 1].Value = Func.FormatNumber_New(AllSumVND);
                xlsSheetEn[rSumVND + j, cSumVND + 1].Value += "(VND)";

                AllSumVND += Convert.ToDecimal(AllSumUSD * Convert.ToDecimal(txtUsdExchange.Text));

                string strMoney = Func.docso(Convert.ToInt32(AllSumVND));
                string strMoneyEn = Func.DocSo_En(Convert.ToInt32(AllSumVND));

                xlsSheet[rContract, cContract].Value = xlsSheet[rContract, cContract].Value.ToString().Replace("{%HOP_DONG%}", contract.Substring(1));
                xlsSheet[rSum + j, cSum].Value = Convert.ToInt32(AllSumVND);

                mCellTmp = new XLCellRange(rSum + j, rSum + j, cSum, cSum + 1);
                xlsSheet.MergedCells.Add(mCellTmp);
                xlsSheet[rSum + j, cSum].Style = xlstStyleSum;
                xlsSheet[rSum + j, cSum + 1].Style = xlstStyleSum;
                xlsSheet[rSumRead + j, cSumRead].Value = xlsSheet[rSumRead + j, cSumRead].Value.ToString().Replace("{%TONG_CHU%}", strMoney.ToUpper());

                xlsSheetEn[rContract, cContract].Value = xlsSheetEn[rContract, cContract].Value.ToString().Replace("{%HOP_DONG%}", contract.Substring(1));
                xlsSheetEn[rSum + j, cSum].Value = Convert.ToInt32(AllSumVND);

                mCellTmp = new XLCellRange(rSum + j, rSum + j, cSum, cSum + 1);
                xlsSheetEn.MergedCells.Add(mCellTmp);
                xlsSheetEn[rSum + j, cSum].Style = xlstStyleSum;
                xlsSheetEn[rSum + j, cSum + 1].Style = xlstStyleSum;
                xlsSheetEn[rSumRead + j, cSumRead].Value = xlsSheetEn[rSumRead + j, cSumRead].Value.ToString().Replace("{%TONG_CHU%}", strMoneyEn.ToUpper());

                xlbBook.Save(fileNameDes);
                ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true);
            }
        }
Exemplo n.º 59
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExport_Click(object sender, EventArgs e)
        {
            string job = "";
            switch (hidJobType.Value)
            {
                case "1":
                    job = "BV";
                    break;
                case "2":
                    job = "VS";
                    break;
                case "3":
                    job = "KT";
                    break;
                case "4":
                    job = "QL";
                    break;

                default:
                    break;
            }
            string buildingId = Func.ParseString(Session["__BUILDINGID__"]);

            Hashtable staffIdRow = new Hashtable();
            string[] dateOfWeekVN = { "T2", "T3", "T4", "T5", "T6", "T7", "CN" };
            string[] dateOfWeekEN = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Sartuday", "Sunday" };

            Dictionary<string, string> dictionary = new Dictionary<string, string>();
            dictionary.Add("monday", "T2");
            dictionary.Add("tuesday", "T3");
            dictionary.Add("wednesday", "T4");
            dictionary.Add("thursday", "T5");
            dictionary.Add("friday", "T6");
            dictionary.Add("saturday", "T7");
            dictionary.Add("sunday", "CN");

            DataSet ds = new DataSet();
            string sql = string.Empty;

            sql = " SELECT *";
            sql += " FROM BD_WorkingWorkedInfo";
            sql += " WHERE BuildingId = '" + buildingId + "' and DelFlag = 0 and jobtypeid = '" + hidJobType.Value + "'";
            sql += " and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'";

            Hashtable scheduleLst = new Hashtable();

            using (SqlDatabase db = new SqlDatabase())
            {
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    db.Close();

                    if (ds != null)
                    {
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            string StaffId = rowType["StaffId"].ToString();
                            string WorkingHourId = rowType["WorkingHourId"].ToString();
                            string WorkingDate = rowType["WorkingDate"].ToString().Substring(6, 2);
                            if (!String.IsNullOrEmpty(WorkingHourId) && scheduleLst.ContainsKey(StaffId + WorkingDate))
                            {
                                scheduleLst.Add(StaffId + WorkingDate, WorkingHourId);
                            }
                        }
                    }
                }
            }

            ds = new DataSet();
            sql = " SELECT *";
            sql += " FROM BD_Staff";
            sql += " WHERE BuildingId = '" + buildingId + "' and DelFlag = 0 and jobtypeid = '" + hidJobType.Value + "' and SUBSTRING(JobBegin,0,7) <= '" + drpYear.SelectedValue + drpMonth.SelectedValue + "' and (JobEnd = '' or JobEnd is Null or SUBSTRING(JobEnd,0,7) >= '" + drpYear.SelectedValue + drpMonth.SelectedValue + "')";
            sql += " Order By Name";

            using (SqlDatabase db = new SqlDatabase())
            {
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);
                    db.Close();

                    if (ds != null)
                    {
                        mvMessage.SetCompleteMessage("File CSV đã xuất thành công.");

                        C1XLBook xlbBook = new C1XLBook();

                        string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\LichLamViec.xls");
                        if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"])))
                        {
                            Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + buildingId));
                        }

                        string strDT = DateTime.Now.ToString("yyyyMMddHHmmss");
                        string strFilePath = @"~\Report\Building\" + buildingId + @"\" + buildingId + "_LichLamViec_" + job + "_" + strDT + "export.xls";
                        string strFilePathExport = @"../../Report/Building/" + buildingId + @"/" + buildingId + "_LichLamViec_" + job + "_" + strDT + "export.xls";

                        string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath);

                        File.Copy(fileName, fileNameDes);

                        xlbBook.Load(fileNameDes);

                        string sheet = "LichLamViec";

                        XLSheet xlsSheet = xlbBook.Sheets[sheet];

                        int i = 0;
                        XLCellRange mrCell = new XLCellRange(0, 0, 1, 2);
                        xlsSheet.MergedCells.Add(mrCell);

                        XLStyle xlstStyle = new XLStyle(xlbBook);
                        xlstStyle.AlignHorz = XLAlignHorzEnum.Center;
                        xlstStyle.Font = new Font("", 12, FontStyle.Bold);
                        xlstStyle.SetBorderColor(Color.Black);
                        xlstStyle.BorderBottom = XLLineStyleEnum.Thin;
                        xlstStyle.BorderTop = XLLineStyleEnum.Thin;
                        xlstStyle.BorderLeft = XLLineStyleEnum.Thin;
                        xlstStyle.BorderRight = XLLineStyleEnum.Thin;

                        xlsSheet[i, 1].Value = "Tháng " + drpMonth.SelectedValue + "/" + drpYear.SelectedValue;
                        xlsSheet[i, 1].Style = xlstStyle;

                        xlsSheet[i + 1, 1].Value = "STT";
                        //xlsSheet[i + 1, 1].Value = "Mã Nhân Viên";
                        xlsSheet[i + 1, 2].Value = "Họ và Tên";

                        XLStyle xlstStyle01 = new XLStyle(xlbBook);
                        xlstStyle01.AlignHorz = XLAlignHorzEnum.Left;
                        xlstStyle01.Font = new Font("", 10, FontStyle.Bold);
                        xlstStyle01.SetBorderColor(Color.Black);
                        xlstStyle01.BorderBottom = XLLineStyleEnum.Thin;
                        xlstStyle01.BorderTop = XLLineStyleEnum.Thin;
                        xlstStyle01.BorderLeft = XLLineStyleEnum.Thin;
                        xlstStyle01.BorderRight = XLLineStyleEnum.Thin;

                        for (int j = 1; j <= 31; j++)
                        {
                            xlsSheet[i, 2 + j].Value = j;
                            DateTime date = new DateTime(Func.ParseInt(drpYear.SelectedValue), Func.ParseInt(drpMonth.SelectedValue), j);
                            xlsSheet[i + 1, 2 + j].Value = dictionary[date.DayOfWeek.ToString().ToLower()];

                            xlsSheet[i, 2 + j].Style = xlstStyle01;
                            xlsSheet[i + 1, 2 + j].Style = xlstStyle01;
                            if (j == DateTime.DaysInMonth(Func.ParseInt(drpYear.SelectedValue), Func.ParseInt(drpMonth.SelectedValue)))
                            {
                                break;
                            }
                        }

                        i++;
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            int No = i;
                            i++;
                            string StaffId = rowType["ID"].ToString();
                            string Name = rowType["Name"].ToString();

                            staffIdRow.Add(StaffId, i);

                            xlsSheet[i, 1].Value = No;
                            xlsSheet[i, 0].Value = StaffId;
                            xlsSheet[i, 2].Value = Name;

                            xlsSheet[i, 0].Style = xlstStyle01;
                            xlsSheet[i, 1].Style = xlstStyle01;
                            xlsSheet[i, 2].Style = xlstStyle01;

                            for (int j = 1; j <= 31; j++)
                            {
                                if (scheduleLst.ContainsKey(StaffId + "" + j.ToString().PadLeft(2, '0')))
                                {
                                    xlsSheet[i, 2 + j].Value = scheduleLst[StaffId + "" + j.ToString().PadLeft(2, '0')];
                                    xlsSheet[i, 2 + j].Style = xlstStyle01;
                                }
                                else
                                {
                                    xlsSheet[i, 2 + j].Style = xlstStyle01;
                                }
                                if (j == DateTime.DaysInMonth(Func.ParseInt(drpYear.SelectedValue), Func.ParseInt(drpMonth.SelectedValue)))
                                {
                                    break;
                                }
                            }
                        }

                        ds = new DataSet();
                        sql = string.Empty;

                        //sql = " SELECT *";
                        //sql += " FROM BD_WorkingWorkedInfo";
                        //sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and DelFlag <> 1 and jobtypeid = '" + hidJobType.Value + "' and YearMonth = '" + drpYear.SelectedValue + drpMonth.SelectedValue + "'";
                        //sql += " Order By StaffId";

                        //using (SqlCommand cm1 = db.CreateCommand(sql))
                        //{
                        //    SqlDataAdapter da1 = new SqlDataAdapter(cm1);
                        //    da1.Fill(ds);
                        //    db.Close();

                        //    if (ds != null)
                        //    {
                        //        xlsSheet[i++ + 1, 2].Value = "Ghi chú:";
                        //        DataTable dt1 = ds.Tables[0];
                        //        foreach (DataRow rowType in dt1.Rows)
                        //        {
                        //            i++;
                        //            string StaffId = rowType["StaffId"].ToString();
                        //            string WorkingHourId = rowType["WorkingHourId"].ToString();
                        //            string WorkingDate = rowType["WorkingDate"].ToString().Substring(6, 2);

                        //            int col = Func.ParseInt(WorkingDate) + 2;
                        //            int row = Func.ParseInt(staffIdRow[StaffId]);
                        //            xlsSheet[row, col].Value = WorkingHourId;
                        //        }
                        //    }
                        //}

                        DataSet ds1 = new DataSet();
                        sql = string.Empty;

                        sql = " SELECT *";
                        sql += " FROM BD_WorkingHour";
                        sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' and DelFlag <> 1 and jobtypeid = '" + hidJobType.Value + "'";
                        sql += " Order By Name";

                        using (SqlCommand cm1 = db.CreateCommand(sql))
                        {
                            SqlDataAdapter da1 = new SqlDataAdapter(cm1);
                            da1.Fill(ds1);
                            db.Close();

                            if (ds != null)
                            {
                                xlsSheet[i++ + 1, 2].Value = "Ghi chú:";
                                DataTable dt1 = ds1.Tables[0];
                                foreach (DataRow rowType in dt1.Rows)
                                {
                                    i++;
                                    string Ma = rowType["WorkingHourId"].ToString();
                                    string Name = rowType["Name"].ToString();
                                    xlsSheet[i, 2].Value = Ma + ":" + Name;
                                }
                                xlsSheet[i + 1, 2].Value = "OFF:nghỉ";
                            }
                        }
                        xlbBook.Save(fileNameDes);
                        ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true);
                    }
                }
            }
        }
        protected void btnView_Click(object sender, EventArgs e)
        {
            C1XLBook xlbBook = new C1XLBook();
            string fileName = HttpContext.Current.Server.MapPath(@"~\Report\Template\BillPhongHop.xlsx");
            if (!Directory.Exists(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"])))
            {
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"])));
            }

            decimal LastSumPriceVND = 0;
            decimal LastSumPriceUSD = 0;

            XLStyle xlstStyle = new XLStyle(xlbBook);
            xlstStyle.AlignHorz = XLAlignHorzEnum.Center;
            xlstStyle.WordWrap = true;
            xlstStyle.Font = new Font("", 8, FontStyle.Regular);
            xlstStyle.SetBorderColor(Color.Black);
            xlstStyle.BorderBottom = XLLineStyleEnum.Thin;
            xlstStyle.BorderTop = XLLineStyleEnum.Thin;
            xlstStyle.BorderLeft = XLLineStyleEnum.Thin;
            xlstStyle.BorderRight = XLLineStyleEnum.Thin;

            string strDT = DateTime.Now.ToString("yyyyMMddHHmmss");
            string strFilePath = @"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\BillPhongHop" + strDT + ".xlsx";
            string strFilePathExport = @"../../Report/Building/" + Func.ParseString(Session["__BUILDINGID__"]) + @"/BillPhongHop" + strDT + ".xlsx";

            string fileNameDes = HttpContext.Current.Server.MapPath(strFilePath);

            //string fileNameDes = HttpContext.Current.Server.MapPath(@"~\Report\Building\" + Func.ParseString(Session["__BUILDINGID__"]) + @"\TongHopDienTich" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx");
            File.Copy(fileName, fileNameDes);

            xlbBook.Load(fileNameDes);
            XLSheet xlsSheet = xlbBook.Sheets["HoaDon"];

            int k = 2;
            xlsSheet[1, 6 + k].Value = xlsSheet[1, 6 + k].Value.ToString().Replace("{%NGAY%}", DateTime.Today.ToString("dd"));
            xlsSheet[1, 6 + k].Value = xlsSheet[1, 6 + k].Value.ToString().Replace("{%THANG%}", DateTime.Today.ToString("MM"));
            xlsSheet[1, 6 + k].Value = xlsSheet[1, 6 + k].Value.ToString().Replace("{%NAM%}", DateTime.Today.ToString("yyyy"));

            using (SqlDatabase db = new SqlDatabase())
            {
                DataSet ds = new DataSet();
                string sql = string.Empty;

                sql = " SELECT Name, ContactName";
                sql += " FROM Customer";
                sql += " WHERE CustomerId = '" + lnbCustomerId.Text + "' ";

                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    if (ds != null)
                    {
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            string Name = rowType[0].ToString();
                            string ContactName = rowType[1].ToString();

                            xlsSheet[6, 0].Value = xlsSheet[6, 0].Value.ToString().Replace("{%TEN_CONG_TY%}", Name);
                            xlsSheet[7, 0].Value = xlsSheet[7, 0].Value.ToString().Replace("{%NGUOI_DAI_DIEN%}", ContactName);

                            xlsSheet[9, 0].Value = xlsSheet[9, 0].Value.ToString().Replace("{%NGAY_HOP_DONG%}", lblBookingDate.Text);

                            xlsSheet[11, 0].Value = xlsSheet[11, 0].Value.ToString().Replace("{%GIO_TU%}", drpHourFrom.SelectedValue);
                            xlsSheet[11, 0].Value = xlsSheet[11, 0].Value.ToString().Replace("{%PHUT_TU%}", drpMinuteFrom.Value);
                            xlsSheet[11, 0].Value = xlsSheet[11, 0].Value.ToString().Replace("{%GIO_DEN%}", drpHourTo.SelectedValue);
                            xlsSheet[11, 0].Value = xlsSheet[11, 0].Value.ToString().Replace("{%PHUT_DEN%}", drpMinuteTo.Value);
                            xlsSheet[11, 0].Value = xlsSheet[11, 0].Value.ToString().Replace("{%NGAY_THUE%}", lblBookingDate.Text);
                        }
                    }
                }

                ds = new DataSet();
                sql = " SELECT Bank,Account,AccountName,Office,OfficeAddress,OfficePhone";
                sql += " FROM Mst_Building";
                sql += " WHERE BuildingId = '" + Func.ParseString(Session["__BUILDINGID__"]) + "' ";
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    if (ds != null)
                    {
                        int tmp = 2;
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            string Bank = rowType["Bank"].ToString();
                            string Account = rowType["Account"].ToString();
                            string AccountName = rowType["AccountName"].ToString();
                            string Office = rowType["Office"].ToString();
                            string OfficeAddress = rowType["OfficeAddress"].ToString();
                            string OfficePhone = rowType["OfficePhone"].ToString();

                            xlsSheet[30 + tmp, 0].Value = xlsSheet[30 + tmp, 0].Value.ToString().Replace("{%VAN_PHONG%}", Office);
                            xlsSheet[31 + tmp, 0].Value = xlsSheet[31 + tmp, 0].Value.ToString().Replace("{%DIEN_THOAI%}", OfficePhone);

                            xlsSheet[33 + tmp, 0].Value = xlsSheet[33 + tmp, 0].Value.ToString().Replace("{%NGAN_HANG%}", Bank);
                            xlsSheet[34 + tmp, 0].Value = xlsSheet[34 + tmp, 0].Value.ToString().Replace("{%TEN_TAI_KHOAN%}", AccountName);
                            xlsSheet[35 + tmp, 0].Value = xlsSheet[35 + tmp, 0].Value.ToString().Replace("{%SO_TAI_KHOAN%}", Account);
                        }
                    }
                }

                xlsSheet[27, 3].Value = Convert.ToDecimal(txtRate.Text);
                xlsSheet[27, 7].Value = txtRateDate.Text.Substring(0, 10);

                ds = new DataSet();
                sql = " SELECT *";
                sql += " FROM v_BookingRoomInfo";
                sql += " WHERE BookingId = '" + hidId.Value + "' ";

                int j = 0;

                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    if (ds != null)
                    {
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            if (j >= 1)
                            {
                                xlsSheet.Rows.Insert(18);
                            }

                            int tmp = 18 + j++;
                            string Name = rowType["Name"].ToString();
                            string Regional = rowType["Regional"].ToString();
                            string Floor = rowType["Floor"].ToString();
                            string Area = rowType["Area"].ToString();
                            string PriceUSD = rowType["PriceUSD"].ToString();
                            string PriceVND = rowType["PriceVND"].ToString();
                            string SumUSD = rowType["SumUSD"].ToString();
                            string SumVND = rowType["SumVND"].ToString();
                            string VatUSD = rowType["VatUSD"].ToString();
                            string VatVND = rowType["VatVND"].ToString();
                            string LastPriceUSD = rowType["LastPriceUSD"].ToString();
                            string LastPriceVND = rowType["LastPriceVND"].ToString();
                            string BookingId = rowType["BookingId"].ToString();

                            xlsSheet[tmp, 1].Value = Name;
                            xlsSheet[tmp, 2].Value = Regional;
                            xlsSheet[tmp, 3].Value = Floor;
                            xlsSheet[tmp, 4].Value = rowType["Area"];
                            xlsSheet[tmp, 5].Value = rowType["PriceUSD"];
                            xlsSheet[tmp, 6].Value = rowType["PriceVND"];
                            xlsSheet[tmp, 7].Value = rowType["SumUSD"];
                            xlsSheet[tmp, 8].Value = rowType["SumVND"];
                            xlsSheet[tmp, 9].Value = rowType["VatUSD"];
                            xlsSheet[tmp, 10].Value = rowType["VatVND"];
                            xlsSheet[tmp, 11].Value = rowType["LastPriceUSD"];
                            xlsSheet[tmp, 12].Value = rowType["LastPriceVND"];

                            LastSumPriceVND += Convert.ToDecimal(rowType["LastPriceVND"]);
                            LastSumPriceUSD += Convert.ToDecimal(rowType["LastPriceUSD"]);

                            for (int col = 1; col <= 12; col++)
                            {
                                xlsSheet[tmp, col].Style = xlstStyle;
                            }
                        }

                    }
                }
                j--;
                XLSheet source = xlbBook.Sheets["tpl"];

                for (int row = 22; row <= 26; row++)
                {
                    for (int col = 1; col <= 12; col++)
                    {
                        xlsSheet[row + j, col].Style = source[row, col].Style;
                        xlsSheet[row + j, col].Value = source[row, col].Value;
                    }
                }

                XLCellRange mrCell = new XLCellRange(22 + j, 23 + j, 1, 1);
                xlsSheet.MergedCells.Add(mrCell);

                mrCell = new XLCellRange(22 + j, 23 + j, 2, 2);
                xlsSheet.MergedCells.Add(mrCell);

                mrCell = new XLCellRange(22 + j, 23 + j, 3, 4);
                xlsSheet.MergedCells.Add(mrCell);

                mrCell = new XLCellRange(22 + j, 22 + j, 5, 6);
                xlsSheet.MergedCells.Add(mrCell);

                mrCell = new XLCellRange(22 + j, 22 + j, 7, 8);
                xlsSheet.MergedCells.Add(mrCell);

                mrCell = new XLCellRange(22 + j, 22 + j, 9, 10);
                xlsSheet.MergedCells.Add(mrCell);

                mrCell = new XLCellRange(22 + j, 22 + j, 11, 12);
                xlsSheet.MergedCells.Add(mrCell);

                ds = new DataSet();
                sql = " SELECT  Service, Mount, PriceUSD, PriceVND, SumUSD, SumVND, VatUSD, VatVND, LastPriceUSD, LastPriceVND, Unit";
                sql += " FROM    PaymentBookingService";
                sql += " WHERE BookingId = '" + hidId.Value + "' ";

                j = 0;
                using (SqlCommand cm = db.CreateCommand(sql))
                {
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    da.Fill(ds);

                    if (ds != null)
                    {
                        DataTable dt = ds.Tables[0];
                        foreach (DataRow rowType in dt.Rows)
                        {
                            if (j >= 1)
                            {
                                xlsSheet.Rows.Insert(19);
                            }
                            int tmp = 24 + j++;

                            string Service = rowType["Service"].ToString();
                            string Mount = rowType["Mount"].ToString();
                            string Unit = rowType["Unit"].ToString();
                            string PriceUSD = rowType["PriceUSD"].ToString();
                            string PriceVND = rowType["PriceVND"].ToString();
                            string SumUSD = rowType["SumUSD"].ToString();
                            string SumVND = rowType["SumVND"].ToString();
                            string VatUSD = rowType["VatUSD"].ToString();
                            string VatVND = rowType["VatVND"].ToString();
                            string LastPriceUSD = rowType["LastPriceUSD"].ToString();
                            string LastPriceVND = rowType["LastPriceVND"].ToString();

                            xlsSheet[tmp, 1].Value = Service;
                            xlsSheet[tmp, 2].Value = rowType["Mount"];
                            xlsSheet[tmp, 3].Value = Unit;

                            xlsSheet[tmp, 5].Value = rowType["PriceUSD"];
                            xlsSheet[tmp, 6].Value = rowType["PriceVND"];
                            xlsSheet[tmp, 7].Value = rowType["SumUSD"];
                            xlsSheet[tmp, 8].Value = rowType["SumVND"];
                            xlsSheet[tmp, 9].Value = rowType["VatUSD"];
                            xlsSheet[tmp, 10].Value = rowType["VatVND"];
                            xlsSheet[tmp, 11].Value = rowType["LastPriceUSD"];
                            xlsSheet[tmp, 12].Value = rowType["LastPriceVND"];

                            LastSumPriceVND += Convert.ToDecimal(rowType["LastPriceVND"]);
                            LastSumPriceUSD += Convert.ToDecimal(rowType["LastPriceUSD"]);

                            for (int col = 1; col <= 12; col++)
                            {
                                xlsSheet[tmp, col].Style = xlstStyle;
                            }
                        }

                    }
                }
                xlsSheet[28 + j - 1, 2].Value = LastSumPriceVND;
                xlsSheet[29 + j - 1, 2].Value = Func.docso(Convert.ToInt32(LastSumPriceVND));

                xlbBook.Save(fileNameDes);
                ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "PopUp('" + strFilePathExport + "'," + PopupWidth + "," + PopupHeight + ",'EditReport', true);", true);
            }
        }