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 wispro.sp.winClient
{
    public partial class frmMerageExcel : Form
    {
        public frmMerageExcel()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            if (fbd.ShowDialog() == DialogResult.OK)
            {
                txtSaveFilePath.Text = System.IO.Path.Combine(fbd.SelectedPath, $"{DateTime.Now.ToString("yyyyMMdd")}-{DateTime.Now.Month - 1}月份绩效计算案件清单.xlsx");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog()
            {
                Multiselect = true,
                Filter = "Excel文件|*.xls;*.xlsx|全部文件|*.*"
            };

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                lstFiles.Items.AddRange(ofd.FileNames);
            }
        }

        public string SaveFilePath { get; set; }
        private void button4_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtSaveFilePath.Text) && lstFiles.Items.Count > 0)
            {

                string[] files = new string[lstFiles.Items.Count];
                for (int i = 0; i < lstFiles.Items.Count; i++)
                {
                    files[i] = lstFiles.Items[i].ToString();
                }

                new wispro.sp.utility.ExcelHelper().MerageExcel(txtSaveFilePath.Text, files);
                SaveFilePath = txtSaveFilePath.Text;
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
