using AR;
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 Project.Dialog
{
    public partial class fSIDQty : Form
    {
        public fSIDQty(string JobSeqDate, string JobSeqNo)
        {
            InitializeComponent();
            var SIDHistoryFiles = PUB.dbmSidHistory.Getfiles(JobSeqDate, JobSeqNo);
            label2.Text = JobSeqDate;
            label3.Text = JobSeqNo;
            label5.Text = "--";
            this.listView1.Items.Clear();

            if (SIDHistoryFiles != null)
                foreach (var file in SIDHistoryFiles)
                {
                    var DT = PUB.dbmSidHistory.GetDatas(new System.IO.FileInfo[] { file });
                    var dr = DT.FirstOrDefault();
                    label5.Text = dr.rev.ToString();
                    var kpc = DT.Sum(t => t.qty) / 1000;
                    var lv = this.listView1.Items.Add(dr.sid);
                    lv.SubItems.Add(kpc.ToString());
                    lv.SubItems.Add(dr.rev.ToString());
                    lv.Tag = file.FullName;
                    if (dr.rev > 0 &&  kpc > dr.rev) lv.ForeColor = Color.Red;
                }

        }

        private void fSIDQty_Load(object sender, EventArgs e)
        {
            this.KeyDown += FSIDQty_KeyDown;
        }

        private void FSIDQty_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape) this.Close();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.listView1.FocusedItem == null) return;
            var file = this.listView1.FocusedItem.Tag.ToString();
            var dlg = UTIL.MsgQ(string.Format("Do you want to delete the following file?\n{0}", file));
            if (dlg != DialogResult.Yes) return;
            System.IO.File.Delete(file);
            this.listView1.Items.Remove(this.listView1.FocusedItem);

        }
    }
}
