using FCOMMON;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FEQ0000
{
    public partial class fPurchaseEBList : fBase
    {
        public fPurchaseEBList(dsPurchase.EETGW_PurchaseEBDataTable dt)
        {
            InitializeComponent();
            Properties.Settings.Default["gwcs"] = FCOMMON.info.CS;
            Properties.Settings.Default["EEEntities"] = FCOMMON.info.CS;

            this.ds1.EETGW_PurchaseEB.Merge(dt);
            this.ds1.AcceptChanges();
        }

        private void fEBoardReport_Load(object sender, EventArgs e)
        {
            EnsureVisibleAndUsableSize();
            this.Show();
            this.bs1.Sort = "sc,sid,pumname";
            this.bs1.Filter = "sc <> ''";
            Application.DoEvents();

            //파일불러오기
            LoadExcel();

            //순번맥기기
            var sumamt = ds1.EETGW_PurchaseEB.Where(t=>t.sc != "").Sum(t => t.pumamt);
            for (int r = 0; r < this.fpSpread1.ActiveSheet.RowCount; r++)
            {
                fpSpread1.ActiveSheet.Cells[r, 0].Value = r + 1;

            }

            //마지막 한줄 추가하고 합계
            fpSpread1.ActiveSheet.AddUnboundRows(fpSpread1.ActiveSheet.RowCount, 1);
            fpSpread1.ActiveSheet.Cells[$"J{fpSpread1.ActiveSheet.RowCount}"].Value = sumamt;
            fpSpread1.ActiveSheet.Cells[$"B{fpSpread1.ActiveSheet.RowCount}"].Value = "Total";
            fpSpread1.ActiveSheet.Cells[$"A{fpSpread1.ActiveSheet.RowCount}:L{fpSpread1.ActiveSheet.RowCount}"].BackColor = Color.FromArgb(220, 220, 220);

        }

        void LoadExcel()
        {
            //파일불러오기
            //var fi = new System.IO.FileInfo(FCOMMON.Util.CurrentPath + "EBoardReport.xlsx");
            //this.fpSpread1.OpenExcel(fi.FullName);
        }

        private void btRefresh_Click(object sender, EventArgs e)
        {
            this.ds1.RejectChanges();
            this.fpSpread1.Invalidate();
        }

        private void btSave_Click(object sender, EventArgs e)
        {

        }

        private void panel1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            LoadExcel();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            //파일저장
            var sd = new SaveFileDialog();
            sd.Filter = "excel|*.xls";
            if (sd.ShowDialog() == DialogResult.OK)
            {
                this.fpSpread1.SaveExcel(sd.FileName, FarPoint.Excel.ExcelSaveFlags.SaveBothCustomRowAndColumnHeaders);
            }
        }
    }
}
