using FarPoint.Win;
using FCOMMON;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Configuration;
using System.Text;
using System.Windows.Forms;

namespace FPJ0000.JobReport_
{
    public partial class K5Dailyform : fBase
    {
        Boolean binit = false;
        public K5Dailyform()
        {
            InitializeComponent();
            this.WindowState = FormWindowState.Maximized;
            this.dts.Value = DateTime.Parse(DateTime.Now.AddMonths(-1).ToString("yyyy-MM-01"));
            this.dte.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-01")).AddDays(-1);
        }

        private void rJobReport_Load(object sender, EventArgs e)
        {
            EnsureVisibleAndUsableSize();
            this.tbProcess.Items.Clear();

            tbProcess.Items.Add("--전체--");
            //var taProcess = new dsReportTableAdapters.ProcessListTableAdapter();
            var dtProcessList = FCOMMON.DBM.GroupUserProcessList();// taProcess.GetData(FCOMMON.info.Login.gcode);
            foreach (var dr in dtProcessList)
                tbProcess.Items.Add(dr);

            //사용자의 공정명을 선택해준다
            this.tbProcess.Text = FCOMMON.info.Login.process;

            //프로세스가 선택되지 않았다면 전체를 선택해준다.
            if (tbProcess.SelectedIndex < 0) tbProcess.SelectedIndex = 0;

            //사용자 목록을 선택한다
            UpdateUserList();

            //엑셀파일불러오기
            //var file = FCOMMON.Util.CurrentPath + "K5DailyForm.xlsx";
            //this.fpSpread1.OpenExcel(file);
            //if (this.fpSpread1.Sheets.Count > 1) this.fpSpread1.ActiveSheetIndex = 0;

            //refrehData();
            //makedata();
            binit = true;
        }

        void UpdateUserList()
        {
            //var db = new EEEntities();

            cmbUser.Items.Clear();
            cmbUser.Items.Add("--전체--");

            //일반사용자 목록 가져온다
            dsJobReport.vJobReportForUserDataTable userlist;
            var db = new dsJobReportTableAdapters.vJobReportForUserTableAdapter();

            if (tbProcess.SelectedIndex <= 0)
            {
                //공정구분없이 전체사용자를 가져온다
                userlist = db.GetNameList(FCOMMON.info.Login.gcode);//.vJobReportForUser.Where(t => t.gcode == FCOMMON.info.Login.gcode).OrderBy(t => t.name).GroupBy(t => t.name);
            }
            else
            {
                userlist = db.GetNameListByProcess(FCOMMON.info.Login.gcode, tbProcess.Text);//.vJobReportForUser.Where(t => t.gcode == FCOMMON.info.Login.gcode && t.userProcess == tbProcess.Text).OrderBy(t => t.name).GroupBy(t => t.name);
            }

            //if (tbProcess.SelectedIndex != 0) userlist = userlist.Where(t => t.processs == tbProcess.Text); //해당 공정의 인원만 처리한다

            foreach (var dr in userlist)
            {
                //var dr = item.First();
                cmbUser.Items.Add(String.Format("[{0}] {1}", dr.id, dr.name));
            }
            if (tbProcess.SelectedIndex > 0)
                cmbUser.Text = string.Format("[{0}] {1}", FCOMMON.info.Login.no, FCOMMON.info.Login.nameK);

            if (cmbUser.SelectedIndex < 0) cmbUser.SelectedIndex = 0;  //기본전체로 선택해준다.
        }

        //void refrehData()
        //{

        //    var db = new EEEntities();


        //    ////조회공정
        //    //this.fpSpread1.Sheets[0].Cells[3, 2].Value = tbProcess.Text;

        //    ////담당자
        //    //this.fpSpread1.Sheets[0].Cells[3, 3].Value = cmbUser.Text;

        //    ////시작일:F4
        //    //this.fpSpread1.Sheets[0].Cells[3, 5].Value = dts.Value;

        //    ////종료일:G4                       
        //    //this.fpSpread1.Sheets[0].Cells[3, 6].Value = dte.Value;

        //    ////근문일수,시간
        //    var vSD = dts.Value.ToString("yyyy-MM-dd");
        //    var vED = dte.Value.ToString("yyyy-MM-dd");

        //    ////휴가일수확인
        //    //var drDays = db.HolidayLIst.Where(t => t.free == false && t.pdate.CompareTo(vSD) >= 0 && t.pdate.CompareTo(vED) <= 0);

        //    ////근무일수적용
        //    //if (drDays == null || drDays.Count() < 1) this.fpSpread1.Sheets[0].Cells[3, 7].Value = 0;
        //    //else this.fpSpread1.Sheets[0].Cells[3, 7].Value = drDays.Count();

        //    ////기준시간 1번시트에 추가 표시 (210215 - 정봉석)
        //    //this.fpSpread1.Sheets[1].Cells["F1"].Value = drDays.Count() * 8;

        //    ComplexBorderSide left = new ComplexBorderSide(Color.Gray, 1);
        //    ComplexBorderSide top = new ComplexBorderSide(Color.Gray, 1);
        //    ComplexBorderSide right = new ComplexBorderSide(Color.Gray, 1);
        //    ComplexBorderSide bottom = new ComplexBorderSide(Color.Gray, 1);

        //    //사용자목록을 가져온다
        //    List<vJobReportForUser> baseData;

        //    //사용자로 그룹해서 수량을 세명 , 사용자 숫자가 된다.
        //    //this.fpSpread1.Sheets[0].Cells[3, 9].Value = baseData.GroupBy(t => t.id).Count(); //인원수

        //    var col = 0;
        //    var row = 0;


        //    //해당 그룹의 기간데이터를 가져온다
        //    if (cmbUser.SelectedIndex > 0)
        //    {
        //        //사용자번호 
        //        var UserNo = cmbUser.Text.Substring(1, cmbUser.Text.IndexOf(']') - 1);
        //        baseData = db.vJobReportForUser.AsNoTracking()
        //            .Where(t => t.gcode == FCOMMON.info.Login.gcode && t.id == UserNo && t.pdate.CompareTo(vSD) >= 0 && t.pdate.CompareTo(vED) <= 0)
        //            .OrderBy(t => t.name)
        //            .OrderBy(t => t.pdate)
        //            .ToList();
        //    }
        //    else if (tbProcess.SelectedIndex > 0)
        //    {
        //        baseData = db.vJobReportForUser.AsNoTracking()
        //            .Where(t => t.gcode == FCOMMON.info.Login.gcode && t.pdate.CompareTo(vSD) >= 0 && t.pdate.CompareTo(vED) <= 0 && t.userProcess == tbProcess.Text)
        //            .OrderBy(t => t.name)
        //            .OrderBy(t => t.pdate)
        //            .ToList();
        //    }
        //    else
        //    {
        //        baseData = db.vJobReportForUser.AsNoTracking()
        //            .Where(t => t.gcode == FCOMMON.info.Login.gcode && t.pdate.CompareTo(vSD) >= 0 && t.pdate.CompareTo(vED) <= 0)
        //            .OrderBy(t => t.name)
        //            .OrderBy(t => t.pdate)
        //            .ToList();
        //    }


        //    row = 5 - 1;

        //    //       this.fpSpread1.Sheets[1].RowCount = baseData.Count + 10;
        //    int no = 1;
        //    this.progressBar1.Value = 0;
        //    this.progressBar1.Maximum = baseData.Count + 1;

        //    this.fpSpread1.ActiveSheetIndex = 1;
        //    this.fpSpread1.ActiveSheet.AutoCalculation = false;
        //    foreach (var item in baseData)
        //    {
        //        col = 1;
        //        var dt = DateTime.Parse(item.pdate);
        //        this.fpSpread1.Sheets[1].Cells[row, col++].Value = no++;

        //        var datestr = string.Format("{0:00}/{1:00}", dt.Month, dt.Day);
        //        this.fpSpread1.Sheets[1].Cells[row, col++].Value = datestr;
        //        this.fpSpread1.Sheets[1].Cells[row, col++].Value = item.requestpart;
        //        this.fpSpread1.Sheets[1].Cells[row, col++].Value = item.package;
        //        this.fpSpread1.Sheets[1].Cells[row, col++].Value = item.status;
        //        this.fpSpread1.Sheets[1].Cells[row, col++].Value = item.type;
        //        this.fpSpread1.Sheets[1].Cells[row, col++].Value = item.process;
        //        this.fpSpread1.Sheets[1].Cells[row, col++].Value = item.projectName;
        //        this.fpSpread1.Sheets[1].Cells[row, col++].Value = item.description;
        //        this.fpSpread1.Sheets[1].Cells[row, col++].Value = item.hrs;
        //        this.fpSpread1.Sheets[1].Cells[row, col++].Value = item.ot;
        //        col++;
        //        col++;
        //        col++;// this.fpSpread1.Sheets[1].Cells[row, col++].Value = item.svalue;
        //        this.fpSpread1.Sheets[1].Cells[row, col++].Value = item.name;
        //        this.progressBar1.Value += 1;
        //        row += 1;
        //    }
        //    this.progressBar1.Value = 0;// += 1;
        //    this.progressBar1.Maximum = fpSpread1.Sheets[1].RowCount + 1;
        //    for (int r = baseData.Count; r < fpSpread1.Sheets[1].RowCount; r++)
        //    {
        //        col = 1;

        //        this.fpSpread1.Sheets[1].Cells[row, col++].Value = string.Empty;
        //        this.fpSpread1.Sheets[1].Cells[row, col++].Value = string.Empty;
        //        this.fpSpread1.Sheets[1].Cells[row, col++].Value = string.Empty;
        //        this.fpSpread1.Sheets[1].Cells[row, col++].Value = string.Empty;
        //        this.fpSpread1.Sheets[1].Cells[row, col++].Value = string.Empty;
        //        this.fpSpread1.Sheets[1].Cells[row, col++].Value = string.Empty;
        //        this.fpSpread1.Sheets[1].Cells[row, col++].Value = string.Empty;
        //        this.fpSpread1.Sheets[1].Cells[row, col++].Value = string.Empty;
        //        this.fpSpread1.Sheets[1].Cells[row, col++].Value = string.Empty;
        //        this.fpSpread1.Sheets[1].Cells[row, col++].Value = string.Empty;
        //        col++;
        //        col++;
        //        col++;// this.fpSpread1.Sheets[1].Cells[row, col++].Value = item.svalue;
        //        this.fpSpread1.Sheets[1].Cells[row, col++].Value = string.Empty;
        //        this.progressBar1.Value = r;
        //        row += 1;
        //    }
        //    this.fpSpread1.ActiveSheet.AutoCalculation = true;
        //    //System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("ko-KR", false);
        //    //FarPoint.Win.Spread.CellType.NumberCellType numberCellType1 = new FarPoint.Win.Spread.CellType.NumberCellType();
        //    //numberCellType1.NegativeRed = true;
        //    //numberCellType1.NullDisplay = "--";

        //    ////합계데이터
        //    //fpSpread1.Sheets[0].Cells[row, 1].Value = "합계";
        //    //fpSpread1.Sheets[0].Cells[row, 1].BackColor = Color.LightGray;
        //    //fpSpread1.Sheets[0].Cells[row, 1].HorizontalAlignment = FarPoint.Win.Spread.CellHorizontalAlignment.Center;
        //    //fpSpread1.Sheets[0].Cells[row, 1].VerticalAlignment = FarPoint.Win.Spread.CellVerticalAlignment.Center;
        //    //fpSpread1.Sheets[0].Cells[row, 1].Border = new ComplexBorder(left, top, right, bottom);
        //    //for (int i = 2; i < 11; i++)
        //    //{
        //    //    char basec = 'C';
        //    //    char newc = (char)(basec + (i - 2));
        //    //    fpSpread1.Sheets[0].Cells[row, i].Formula = "SUM(" + newc.ToString() + "8:" + newc.ToString() + row.ToString() + ")";
        //    //    fpSpread1.Sheets[0].Cells[row, i].BackColor = Color.LightGray;


        //    //    fpSpread1.Sheets[0].Cells[row, i].CellType = numberCellType1;
        //    //    fpSpread1.Sheets[0].Cells[row, i].ParseFormatString = "N1";
        //    //    fpSpread1.Sheets[0].Cells[row, i].CellType = numberCellType1;
        //    //    fpSpread1.Sheets[0].Cells[row, i].ParseFormatString = "N1";


        //    //    fpSpread1.Sheets[0].Cells[row, i].Border = new ComplexBorder(left, top, right, bottom);
        //    //    fpSpread1.Sheets[0].Cells[row, i].HorizontalAlignment = FarPoint.Win.Spread.CellHorizontalAlignment.Center;
        //    //    fpSpread1.Sheets[0].Cells[row, i].VerticalAlignment = FarPoint.Win.Spread.CellVerticalAlignment.Center;

        //    //}

        //    //this.fpSpread1.Sheets[0].RowCount = row + 1;


        //}
        private void button1_Click(object sender, EventArgs e)
        {
            //refrehData();
            makedata();
        }

        void makedata()
        {
            this.dsReport.K5DailyForm.Clear();
            this.progressBar1.Value = 0;





            //자료를 불러온다
            var sd = dts.Value.ToString("yyyy-MM-dd");// DateTime.Parse(dtSD.Text).ToString("yyyy-MM-dd");
            var ed = dte.Value.ToString("yyyy-MM-dd"); // DateTime.Parse(dtED.Text).ToString("yyyy-MM-dd");
            var db = new dsJobReportTableAdapters.vJobReportForUserTableAdapter();// EEEntities();

            var gcode = "EET1P";
            if (String.IsNullOrEmpty(FCOMMON.info.Login.gcode) == false)
                gcode = FCOMMON.info.Login.gcode;

            var rawdata = db.GetByDate(FCOMMON.info.Login.gcode, sd, ed).OrderBy(t => t.pdate).GroupBy(t => t.pdate);// ..vJobReportForUser.AsNoTracking()
                //.Where(t => t.gcode == gcode && t.pdate.CompareTo(sd) >= 0 && t.pdate.CompareTo(ed) <= 1)
                //.OrderBy(t => t.pdate).GroupBy(t => t.pdate).ToList();
            //ta.Fill(this.dsReport.vJobReportForUser, FCOMMON.info.Login.gcode, sd.ToString("yyyy-MM-dd"), ed.ToShortTimeString());


            var col = 3;
            var sheet = this.fpSpread1.Sheets[0];
            sheet.ColumnCount = 3 + rawdata.Count();
            foreach (var item in rawdata)
            {
                sheet.Cells[3, col].Value = item.First().ww;
                sheet.Cells[4, col].Value = item.Key.Substring(8, 2);
                col += 1;
            }


            this.progressBar1.Maximum = rawdata.Count();
            //날짜별로 묶음처리한다.
            //var grplist = rawdata.GroupBy(t => t.pdate);

            ComplexBorderSide left = new ComplexBorderSide(Color.Gray, 1);
            ComplexBorderSide top = new ComplexBorderSide(Color.Gray, 1);
            ComplexBorderSide right = new ComplexBorderSide(Color.Gray, 1);
            ComplexBorderSide bottom = new ComplexBorderSide(Color.Gray, 1);



            col = 3;
            foreach (var item in rawdata)
            {

                var row = 5;
                this.progressBar1.Value += 1;
                var drDate = item.FirstOrDefault();

                //근무일원
                var 근무인원 = item.GroupBy(t => t.id).Count();

                //완료
                //var newdr = this.dsReport.K5DailyForm.NewK5DailyFormRow();
                //newdr.Grp = "1.Tech. Support Summary";
                //newdr.Item = "1.Completed";
                //newdr.ww = item.Key.Substring(2, 2) + "-" + int.Parse(drDate.ww).ToString("00");
                //newdr.Format = "N0";
                //newdr.Sign = string.Empty;
                //newdr.pdate = int.Parse(item.Key.Substring(8, 2)).ToString("00");
                //newdr.value = item.Where(t => t.svalue == "Technical Support" && t.status == "진행 완료").Count();
                //newdr.graph = true;
                //dsReport.K5DailyForm.AddK5DailyFormRow(newdr);

                sheet.Cells[row++, col].Value = item.Where(t => t.svalue == "Technical Support" && t.status == "진행 완료").Count(); // item.First().ww;


                //진행중
                //var newdr2 = this.dsReport.K5DailyForm.NewK5DailyFormRow();
                //newdr2.Grp = "1.Tech. Support Summary";
                //newdr2.Item = "2.On-going";
                //newdr2.Format = "N0";
                //newdr2.Sign = string.Empty;
                //newdr2.ww = item.Key.Substring(2, 2) + "-" + int.Parse(drDate.ww).ToString("00");
                //newdr2.pdate = int.Parse(item.Key.Substring(8, 2)).ToString("00");
                //newdr2.value = item.Where(t => t.svalue == "Technical Support" && t.status != "진행 완료").Count();
                //newdr2.graph = true;
                //dsReport.K5DailyForm.AddK5DailyFormRow(newdr2);

                sheet.Cells[row++, col].Value = item.Where(t => t.svalue == "Technical Support" && t.status != "진행 완료").Count();

                //건수
                //var newdr3 = this.dsReport.K5DailyForm.NewK5DailyFormRow();
                //newdr3.Grp = "1.Tech. Support Summary";
                //newdr3.Item = "3.건수";
                //newdr3.Format = "N0";
                //newdr3.Sign = string.Empty;
                //newdr3.ww = item.Key.Substring(2, 2) + "-" + int.Parse(drDate.ww).ToString("00");
                //newdr3.pdate = int.Parse(item.Key.Substring(8, 2)).ToString("00");
                //newdr3.value = item.Where(t => t.svalue == "Technical Support").Count();
                //newdr3.graph = true;
                //dsReport.K5DailyForm.AddK5DailyFormRow(newdr3);

                sheet.Cells[row++, col].Value = item.Where(t => t.svalue == "Technical Support").Count();

                //hrs
                //var newdr4 = this.dsReport.K5DailyForm.NewK5DailyFormRow();
                //newdr4.Grp = "1.Tech. Support Summary";
                //newdr4.Item = "4.Hrs";
                //newdr4.Format = "N0";
                //newdr4.Sign = string.Empty;
                //newdr4.ww = item.Key.Substring(2, 2) + "-" + int.Parse(drDate.ww).ToString("00");
                //newdr4.pdate = int.Parse(item.Key.Substring(8, 2)).ToString("00");
                var newdr4value = (double)(item.Where(t => t.svalue == "Technical Support").Sum(t => t.hrs));
                //newdr4.graph = false;
                //dsReport.K5DailyForm.AddK5DailyFormRow(newdr4);
                sheet.Cells[row++, col].Value = (double)(item.Where(t => t.svalue == "Technical Support").Sum(t => t.hrs));

                //요약
                //var newdr4a = this.dsReport.K5DailyForm.NewK5DailyFormRow();
                //newdr4a.Grp = "1.Tech. Support Summary";
                //newdr4a.Item = "5.Technical Support";
                //newdr4a.Format = "N1";
                //newdr4a.Sign = "%";
                //newdr4a.ww = item.Key.Substring(2, 2) + "-" + int.Parse(drDate.ww).ToString("00");
                //newdr4a.pdate = int.Parse(item.Key.Substring(8, 2)).ToString("00");
                //newdr4a.value = Math.Round((newdr4value / (근무인원 * 8.0)) * 100.0, 2);
                //newdr4a.graph = true;
                //dsReport.K5DailyForm.AddK5DailyFormRow(newdr4a);
                sheet.Cells[row++, col].Value = Math.Round((newdr4value / (근무인원 * 8.0)) * 100.0, 3);

                //Other Job Portion
                //var newdr5 = this.dsReport.K5DailyForm.NewK5DailyFormRow();
                //newdr5.Grp = "2.Other Job Portion";
                //newdr5.Item = "1.Project";
                //newdr5.Format = "N0";
                //newdr5.Sign = string.Empty;
                //newdr5.ww = item.Key.Substring(2, 2) + "-" + int.Parse(drDate.ww).ToString("00");
                //newdr5.pdate = int.Parse(item.Key.Substring(8, 2)).ToString("00");
                var newdr5value = (double)(item.Where(t => t.svalue == "Project").Sum(t => t.hrs));
                //newdr5.graph = false;
                //dsReport.K5DailyForm.AddK5DailyFormRow(newdr5);
                sheet.Cells[row++, col].Value = (double)(item.Where(t => t.svalue == "Project").Sum(t => t.hrs));

                //Other Job Portion
                //var newdr6 = this.dsReport.K5DailyForm.NewK5DailyFormRow();
                //newdr6.Grp = "2.Other Job Portion";
                //newdr6.Item = "2.Training";
                //newdr6.Format = "N0";
                //newdr6.Sign = string.Empty;
                //newdr6.ww = item.Key.Substring(2, 2) + "-" + int.Parse(drDate.ww).ToString("00");
                //newdr6.pdate = int.Parse(item.Key.Substring(8, 2)).ToString("00");
                var newdr6value = (double)(item.Where(t => t.svalue == "Training").Sum(t => t.hrs));
                //newdr6.graph = false;
                //dsReport.K5DailyForm.AddK5DailyFormRow(newdr6);
                sheet.Cells[row++, col].Value = (double)(item.Where(t => t.svalue == "Training").Sum(t => t.hrs));


                //Overhaul
                //var newdr7 = this.dsReport.K5DailyForm.NewK5DailyFormRow();
                //newdr7.Grp = "2.Other Job Portion";
                //newdr7.Item = "3.Overhaul";
                //newdr7.Format = "N0";
                //newdr7.Sign = string.Empty;
                //newdr7.ww = item.Key.Substring(2, 2) + "-" + int.Parse(drDate.ww).ToString("00");
                //newdr7.pdate = int.Parse(item.Key.Substring(8, 2)).ToString("00");
                var newdr7value = (double)(item.Where(t => t.svalue == "Overhaul").Sum(t => t.hrs));
                //newdr7.graph = false;
                //dsReport.K5DailyForm.AddK5DailyFormRow(newdr7);
                sheet.Cells[row++, col].Value = (double)(item.Where(t => t.svalue == "Overhaul").Sum(t => t.hrs));


                //Others
                //var newdr8 = this.dsReport.K5DailyForm.NewK5DailyFormRow();
                //newdr8.Grp = "2.Other Job Portion";
                //newdr8.Item = "4.Others";
                //newdr8.Format = "N0";
                //newdr8.Sign = string.Empty;
                //newdr8.ww = item.Key.Substring(2, 2) + "-" + int.Parse(drDate.ww).ToString("00");
                //newdr8.pdate = int.Parse(item.Key.Substring(8, 2)).ToString("00");
                var newdr8value = (double)(item.Where(t => t.svalue != "Project" && t.svalue != "Training" && t.svalue != "Overhaul").Sum(t => t.hrs));
                //newdr8.graph = false;
                //dsReport.K5DailyForm.AddK5DailyFormRow(newdr8);
                sheet.Cells[row++, col].Value = (double)(item.Where(t => t.svalue == "Others").Sum(t => t.hrs));

                //Other Job Portion
                //var newdr10 = this.dsReport.K5DailyForm.NewK5DailyFormRow();
                //newdr10.Grp = "2.Other Job Portion";
                //newdr10.Item = "5.Project";
                //newdr10.Format = "N1";
                //newdr10.Sign = "%";
                //newdr10.ww = item.Key.Substring(2, 2) + "-" + int.Parse(drDate.ww).ToString("00");
                //newdr10.pdate = int.Parse(item.Key.Substring(8, 2)).ToString("00");
                //newdr10.value = (newdr5value / (근무인원 * 8)) * 100.0;
                //newdr10.graph = false;
                //dsReport.K5DailyForm.AddK5DailyFormRow(newdr10);
                sheet.Cells[row++, col].Value = Math.Round((newdr5value / (근무인원 * 8)) * 100.0, 3);


                //Other Job Portion
                //newdr10 = this.dsReport.K5DailyForm.NewK5DailyFormRow();
                //newdr10.Grp = "2.Other Job Portion";
                //newdr10.Item = "6.Training";
                //newdr10.Format = "N1";
                //newdr10.Sign = "%";
                //newdr10.ww = item.Key.Substring(2, 2) + "-" + int.Parse(drDate.ww).ToString("00");
                //newdr10.pdate = int.Parse(item.Key.Substring(8, 2)).ToString("00");
                //newdr10.value = (newdr6.value / (근무인원 * 8)) * 100.0;
                //newdr10.graph = false;
                //dsReport.K5DailyForm.AddK5DailyFormRow(newdr10);
                sheet.Cells[row++, col].Value = Math.Round((newdr6value / (근무인원 * 8)) * 100.0, 3);


                //Overhaul
                //newdr10 = this.dsReport.K5DailyForm.NewK5DailyFormRow();
                //newdr10.Grp = "2.Other Job Portion";
                //newdr10.Item = "7.Overhaul";
                //newdr10.Format = "N1";
                //newdr10.Sign = "%";
                //newdr10.ww = item.Key.Substring(2, 2) + "-" + int.Parse(drDate.ww).ToString("00");
                //newdr10.pdate = int.Parse(item.Key.Substring(8, 2)).ToString("00");
                //newdr10.value = (newdr7.value / (근무인원 * 8)) * 100.0;
                //newdr10.graph = false;
                //dsReport.K5DailyForm.AddK5DailyFormRow(newdr10);
                sheet.Cells[row++, col].Value = Math.Round((newdr7value / (근무인원 * 8)) * 100.0, 3);


                //Others
                //newdr10 = this.dsReport.K5DailyForm.NewK5DailyFormRow();
                //newdr10.Grp = "2.Other Job Portion";
                //newdr10.Item = "8.Others";
                //newdr10.Format = "N1";
                //newdr10.Sign = "%";
                //newdr10.ww = item.Key.Substring(2, 2) + "-" + int.Parse(drDate.ww).ToString("00");
                //newdr10.pdate = int.Parse(item.Key.Substring(8, 2)).ToString("00");
                //newdr10.value = (newdr8.value / (근무인원 * 8)) * 100.0;
                //newdr10.graph = false;
                //dsReport.K5DailyForm.AddK5DailyFormRow(newdr10);
                sheet.Cells[row++, col].Value = Math.Round((newdr8value / (근무인원 * 8)) * 100.0, 3);


                //Others TTL
                //newdr10 = this.dsReport.K5DailyForm.NewK5DailyFormRow();
                //newdr10.Grp = "2.Other Job Portion";
                //newdr10.Item = "9.Others TTL";
                //newdr10.Format = "N0";
                //newdr10.Sign = "";
                //newdr10.ww = item.Key.Substring(2, 2) + "-" + int.Parse(drDate.ww).ToString("00");
                //newdr10.pdate = int.Parse(item.Key.Substring(8, 2)).ToString("00");
                //newdr10.value = newdr5.value + newdr6.value + newdr7.value + newdr8.value;
                //newdr10.graph = false;
                //dsReport.K5DailyForm.AddK5DailyFormRow(newdr10);
                sheet.Cells[row++, col].Value = newdr5value + newdr6value + newdr7value + newdr8value;


                //Others TTL (%)
                //newdr10 = this.dsReport.K5DailyForm.NewK5DailyFormRow();
                //newdr10.Grp = "2.Other Job Portion";
                //newdr10.Item = "9.Others TTL(%)";
                //newdr10.Format = "N1";
                //newdr10.Sign = "%";
                //newdr10.ww = item.Key.Substring(2, 2) + "-" + int.Parse(drDate.ww).ToString("00");
                //newdr10.pdate = int.Parse(item.Key.Substring(8, 2)).ToString("00");
                //newdr10.value = (newdr5.value / (근무인원 * 8) + newdr6.value / (근무인원 * 8) + newdr7.value / (근무인원 * 8) + newdr8.value / (근무인원 * 8)) * 100.0;
                //newdr10.graph = false;
                //dsReport.K5DailyForm.AddK5DailyFormRow(newdr10);
                sheet.Cells[row++, col].Value = Math.Round((newdr5value / (근무인원 * 8) + newdr6value / (근무인원 * 8) + newdr7value / (근무인원 * 8) + newdr8value / (근무인원 * 8)) * 100.0, 3);


                //3.근무인원
                //newdr10 = this.dsReport.K5DailyForm.NewK5DailyFormRow();
                //newdr10.Grp = "3.근무인원";
                //newdr10.Item = "1.(8hrs/p.s)";
                //newdr10.Format = "N0";
                //newdr10.Sign = "";
                //newdr10.ww = item.Key.Substring(2, 2) + "-" + int.Parse(drDate.ww).ToString("00");
                //newdr10.pdate = int.Parse(item.Key.Substring(8, 2)).ToString("00");
                //newdr10.value = 근무인원;
                //newdr10.graph = false;
                //dsReport.K5DailyForm.AddK5DailyFormRow(newdr10);
                sheet.Cells[row++, col].Value = 근무인원;


                //3.근무인원
                var v1 = (newdr4value / (근무인원 * 8.0)) * 100.0;
                var v2 = (newdr5value / (근무인원 * 8) + newdr6value / (근무인원 * 8) + newdr7value / (근무인원 * 8) + newdr8value / (근무인원 * 8)) * 100.0;

                //newdr10 = this.dsReport.K5DailyForm.NewK5DailyFormRow();
                //newdr10.Grp = "4.TTL";
                //newdr10.Item = "1.Working Utilization(%)";
                //newdr10.Format = "N1";
                //newdr10.Sign = "%";
                //newdr10.ww = item.Key.Substring(2, 2) + "-" + int.Parse(drDate.ww).ToString("00");
                //newdr10.pdate = int.Parse(item.Key.Substring(8, 2)).ToString("00");
                //newdr10.value = v1 + v2;
                //newdr10.graph = true;
                //dsReport.K5DailyForm.AddK5DailyFormRow(newdr10);
                sheet.Cells[row++, col].Value = Math.Round(v1 + v2, 3);

                col += 1;

            }

            //중앙정렬 및 테두리 작업
            this.progressBar1.Maximum = sheet.RowCount * sheet.ColumnCount;
            this.progressBar1.Value = 0;
            sheet.AutoCalculation = false;
            for (int row = 0; row < sheet.RowCount; row++)
            {
                for (int c = 0; c < sheet.ColumnCount; c++)
                {
                    this.progressBar1.Value += 1;
                    sheet.Cells[row, c].Border = new ComplexBorder(left, top, right, bottom);
                    sheet.Cells[row, c].HorizontalAlignment = FarPoint.Win.Spread.CellHorizontalAlignment.Center;
                    sheet.Cells[row, c].VerticalAlignment = FarPoint.Win.Spread.CellVerticalAlignment.Center;
                    Application.DoEvents();
                }
            }
            sheet.AutoCalculation = true;
            //this.reportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.Normal);
            //this.reportViewer1.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.PageWidth;
            //this.reportViewer1.RefreshReport();

            //var asheet = this.fpSpread1.Sheets[1];
            //asheet.RowCount = dsReport.K5DailyForm.Rows.Count + 2;
            //int row = 0;            
            //foreach(dsReport.K5DailyFormRow dr in this.dsReport.K5DailyForm.Rows)
            //{
            //    var sheet = this.fpSpread1.Sheets[1];
            //    sheet.Cells[row + 0, 0].Value = row.ToString();
            //    sheet.Cells[row + 0, 1].Value = dr.ww;                
            //    sheet.Cells[row + 0, 2].Value = dr.Grp;
            //    sheet.Cells[row + 0, 3].Value = dr.pdate;
            //    sheet.Cells[row + 0, 4].Value = dr.Item;
            //    sheet.Cells[row + 0, 5].Value = dr.value;
            //    row += 1;
            //}
        }

        private void tbProcess_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (binit == false) return;
            UpdateUserList();
            //if (tbProcess.SelectedIndex >= 0) refrehData();
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void btSave_Click(object sender, EventArgs e)
        {
            var sd = new SaveFileDialog();
            sd.Filter = "excel(*.xls)|*.xls";
            sd.FilterIndex = 0;
            sd.FileName = "적정인원관리.xls";
            if (sd.ShowDialog() == DialogResult.OK)
            {
                fpSpread1.SaveExcel(sd.FileName);
                FCOMMON.Util.MsgE("파일저장완료\n" + sd.FileName);
            }
        }
    }
}
