using System;
using System.Drawing;
using System.Windows.Forms;
using System.Linq;
using System.Collections.Generic;

namespace Project.Dialog
{
	public partial class fFinishJob : Form
	{


		string jobseqDate = string.Empty;
		string jobseqNo = string.Empty;

		Class.CHistoryJOB JObHistory = null;
		List<UIControl.CItem> OUTHistory = null;

		//arCtl.arLabel[] lbl_seq;
		//Dialog.fBlurPanel fb;
		DateTime JobStartTime, JobEndTime;

		public string Command = string.Empty;

		public fFinishJob(DateTime JobStarttime_, DateTime JobEndtime_, string jobseqDate_, string jobseqNo_,
			Class.CHistoryJOB histJ_,
			DataSet1.SIDHistoryDataTable histS_, List<UIControl.CItem> histO)
		{
			InitializeComponent();
			JobStartTime = JobStarttime_;
			JobEndTime = JobEndtime_;
			this.JObHistory = histJ_;
			this.OUTHistory = histO;

			this.KeyPreview = true;
			this.KeyDown += (s1, e1) =>
			{
				if (e1.KeyCode == Keys.Escape)
				{
					Close();
				}
			};
			jobseqDate = jobseqDate_;
			jobseqNo = jobseqNo_;


			if (System.Diagnostics.Debugger.IsAttached == false)
			{
				//fb = new Dialog.fBlurPanel();
				//fb.Show();
			}


			//Pub.flag.set(eFlag.SCR_JOBFINISH, true, "SCR_FINSHJOB");
			this.FormClosed += fFinishJob_FormClosed;
		}

		void fFinishJob_FormClosed(object sender, FormClosedEventArgs e)
		{
			// Comm.WebService.Message -= WebService_Message;
		}

		private void button1_Click(object sender, EventArgs e)
		{
			this.Close();
		}

		private void __LoaD(object sender, EventArgs e)
		{
			this.Text = string.Format("금일 작업 목록 입니다({0})", DateTime.Now.ToShortDateString());

			int cntl = 0;
			int cntr = 0;
			float qty = 0;

			if (Pub.setting.OnlineMode)
				using (var db = new EEEntities())
				{
					var sd = DateTime.Parse(DateTime.Now.ToShortDateString() + " 00:00:00");
					var ed = DateTime.Parse(DateTime.Now.ToShortDateString() + " 23:59:59");

					if (Pub.Result.JobStartTime.Year != 1982) sd = Pub.Result.JobStartTime;
					if (Pub.Result.JobEndTime.Year != 1982) ed = Pub.Result.JobEndTime;

					label1.Text = string.Format("작업기간 {0}~{1}", sd.ToString("HH:mm:ss"), ed.ToString("HH:mm:ss"));

					var list = db.Component_Reel_Result.Where(t => t.STIME >= sd && t.STIME <= ed && t.PRNVALID == true && t.PRNATTACH == true);
					if (list != null && list.Count() > 0)
					{
						cntl = list.Where(t => t.LOC == "L").GroupBy(t => t.RID0).Count();
						cntr = list.Where(t => t.LOC == "R").GroupBy(t => t.RID0).Count();
					}
					int? dbqty = list.Sum(t => t.QTY);
					if (dbqty != null) qty = ((int)dbqty);
				}
			lbCntL.Text = cntl.ToString();
			lbCntR.Text = cntr.ToString();
			lbSumQty.Text = qty.ToString();
		}

	}
}
