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.Text;
using System.Windows.Forms;

namespace FPJ0000.JobReport_
{
    public partial class fJobChartMenu : fBase
    {
        Boolean binit = false;
        int curLevel = 0;// Math.Max(FCOMMON.info.Login.level, FCOMMON.DBM.getAuth(FCOMMON.DBM.eAuthType.jobreport));
        public fJobChartMenu()
        {
            InitializeComponent();

            Properties.Settings.Default["gwcs"] = FCOMMON.info.CS;
            Properties.Settings.Default["EEEntities"] = FCOMMON.info.CS;
            Properties.Settings.Default["EEEntitiesLayout"] = FCOMMON.info.CS;
            curLevel = Math.Max(FCOMMON.info.Login.level, FCOMMON.DBM.getAuth(FCOMMON.DBM.eAuthType.jobreport));

            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 fJobChartMenu_Load(object sender, EventArgs e)
        {
            EnsureVisibleAndUsableSize();
            this.cmbProcess.Items.Clear();

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

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

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

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

            //엑셀파일불러오기
            this.Show();
            Application.DoEvents();

            var file = FCOMMON.Util.CurrentPath + "ReportProjectSummary.xlsx";
            this.fpSpread1.OpenExcel(file);
            if (this.fpSpread1.Sheets.Count > 1) this.fpSpread1.ActiveSheetIndex = 0;

            //refrehData();
            binit = true;
            btSave.Enabled = true;
            btRefresh.Enabled = true;

            if(curLevel < 5)
            {
                this.cmbProcess.Enabled = false;
                cmbUser.Enabled = false;
            }
        }
        void UpdateUserList()
        {
            //          var db = new EEEntities();

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

            var userList = FCOMMON.DBM.getActiveUserTable(1);



            //일반사용자 목록 가져온다
            //IQueryable<IGrouping<String, vJobReportForUser>> userlist;

            //공정구분없이 전체사용자를 가져온다
            foreach (System.Data.DataRow item in userList.Rows)
            {
                var id = item.Field<string>("id");
                var dispname = item.Field<string>("dispname");
                var process = item.Field<string>("process");
                if (cmbProcess.SelectedIndex > 0 && cmbProcess.Text.Equals(process) == false) continue;
                cmbUser.Items.Add(dispname);
            }

            //if (tbProcess.SelectedIndex <= 0)
            //{

            //}
            //else
            //{
            //    userlist = db.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); //해당 공정의 인원만 처리한다


            if (cmbProcess.SelectedIndex > 0)
                cmbUser.Text = string.Format("{1}({0})", FCOMMON.info.Login.no, FCOMMON.info.Login.nameK);

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

        string getUserID()
        {
            var si = cmbUser.Text.LastIndexOf("(");
            var ei = cmbUser.Text.LastIndexOf(")");
            var retval = cmbUser.Text.Substring(si + 1, ei - si - 1);
            return retval;
        }
        void refrehData()
        {
            //var db = new EEEntities();

            progressBar1.Value = 0;
            progressBar1.Maximum = 10;


            fpSpread1.Visible = false;

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

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

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

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

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

            //휴가일수확인
            var taHolidylist = new dsJobReportTableAdapters.HolidayLIstTableAdapter();
            var drDays = taHolidylist.GetData(vSD, vED).Where(t => t.IsfreeNull() || t.free == false);// 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, 6].Value = 0;
            else this.fpSpread1.Sheets[0].Cells[3, 6].Value = drDays.Count();


            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);

            //사용자목록을 가져온다
          
            var userCount = 0;
            var taJobreportuser = new dsJobReportTableAdapters.vJobReportForUserTableAdapter();
            if (cmbUser.SelectedIndex > 0)
            {
                //사용자번호 
                var UserNo = getUserID();// cmbUser.Text.Substring(1, cmbUser.Text.IndexOf(']') - 1);
                userCount = 1;// db.vJobReportForUser.Where(t => t.gcode == FCOMMON.info.Login.gcode && t.id == UserNo).GroupBy(t=>t.id).Count();
            }
            else if (cmbProcess.SelectedIndex > 0)
            {
                userCount = (int)taJobreportuser.GetProcessUserCount(FCOMMON.info.Login.gcode,cmbProcess.Text);// db.vJobReportForUser.Where(t => t.gcode == FCOMMON.info.Login.gcode && t.userProcess == tbProcess.Text).GroupBy(t => t.id).Count();
            }
            else
            {
                userCount = (int)taJobreportuser.GetUserCount(FCOMMON.info.Login.gcode);// db.vJobReportForUser.Where(t => t.gcode == FCOMMON.info.Login.gcode).GroupBy(t => t.id).Count();
            }


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

            var col = 0;
            var row = 0;


            //해당 그룹의 기간데이터를 가져온다
            dsJobReport.vJobReportForUserDataTable baseData;
            if (cmbUser.SelectedIndex > 0)
            {
                //사용자번호 
                var UserNo = getUserID();// cmbUser.Text.Substring(1, cmbUser.Text.IndexOf(']') - 1);
                baseData = taJobreportuser.GetDataID(FCOMMON.info.Login.gcode, UserNo, vSD, vED); // db.vJobReportForUser
                    //.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 (cmbProcess.SelectedIndex > 0)
            {
                baseData = taJobreportuser.GetByProcess(FCOMMON.info.Login.gcode, cmbProcess.Text, vSD, vED);// db.vJobReportForUser
                    //.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 = taJobreportuser.GetByDate(FCOMMON.info.Login.gcode, vSD, vED);// db.vJobReportForUser
                    //.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();
            }

            col = 0;
            row = 1;
            fpSpread1.Sheets[1].RowCount = baseData.GroupBy(t => t.id).Count() + 1;
            foreach (var item in baseData.GroupBy(t => t.id)) //사용자별로 그룹을 해서
            {
                var dr = item.FirstOrDefault();
                if (row <= this.fpSpread1.Sheets[2].RowCount)
                    this.fpSpread1.Sheets[2].RowCount = Math.Max(100, row);

                if(row < this.fpSpread1.Sheets[2].RowCount)
                {
                    this.fpSpread1.Sheets[2].Cells[row, 0].Value = dr.name;
                    this.fpSpread1.Sheets[2].Cells[row, 1].Value = dr.id;
                    this.fpSpread1.Sheets[2].Cells[row, 2].Value = item.Sum(t => t.hrs);
                    this.fpSpread1.Sheets[2].Cells[row, 3].Value = item.Sum(t => t.ot);
                }
                else
                {

                }
                
                row += 1;
            }
            fpSpread1.Sheets[1].ColumnCount = 5;
            fpSpread1.Sheets[1].RowCount = row + 1;

            //Raw dat a표시
            row = 1;
            this.fpSpread1.Sheets[2].RowCount = baseData.Count + 1;
            foreach (var item in baseData)
            {
                col = 0;
                this.fpSpread1.Sheets[3].Cells[row, col++].Value = item.id;
                this.fpSpread1.Sheets[3].Cells[row, col++].Value = item.name;
                this.fpSpread1.Sheets[3].Cells[row, col++].Value = item.pdate;
                this.fpSpread1.Sheets[3].Cells[row, col++].Value = item.userProcess;
                this.fpSpread1.Sheets[3].Cells[row, col++].Value = item.process;
                this.fpSpread1.Sheets[3].Cells[row, col++].Value = item.svalue;
                this.fpSpread1.Sheets[3].Cells[row, col++].Value = item.hrs;
                this.fpSpread1.Sheets[3].Cells[row, col++].Value = item.ot;
                this.fpSpread1.Sheets[3].Cells[row, col++].Value = item.requestpart;
                this.fpSpread1.Sheets[3].Cells[row, col++].Value = item.package;
                row += 1;
            }

            // var dtRaw = db.vJobReportForUser.Where(t => t.gcode == FCOMMON.info.Login.gcode && t.pdate.CompareTo(vSD) >= 0 && t.pdate.CompareTo(vED) <= 0);

            //공정목록(우측으로 전개함)
            col = 2;
            var orTypeName = baseData.Where(t => t.svalue != "휴가").OrderBy(t => t.process).GroupBy(t => t.process);
            this.fpSpread1.ActiveSheetIndex = 0;
            foreach (var item in orTypeName)
            {
                var dr = item.FirstOrDefault();
                this.fpSpread1.Sheets[0].Cells[6, col++].Value = dr.process;
                if (col == 82) break; //목록개수를 넘었으니 더이상 진행하지 못한다 이것들은 모두 ETC에 넣는다
                //col += 1;
            }

            //나머지 열을 * 로 채운다
            for (int i = col; i < 82; i++)
            {
                this.fpSpread1.Sheets[0].Cells[6, i].Value = "*";
                this.fpSpread1.Sheets[0].Columns[i].Visible = (i < 8);//.Cells[6, i].Value = "*";
            }



            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 = "--";


            //프로세스목록을 먼저 기록한다
            row = 7;
            var orProcess = baseData.OrderBy(t => t.requestpart).GroupBy(t => t.requestpart);
            this.fpSpread1.Sheets[0].RowCount = 7 + orProcess.Count() + 1;

            progressBar1.Value = 0;
            progressBar1.Maximum = orProcess.Count();
            foreach (var item in orProcess)
            {
                progressBar1.Value += 1;
                var RequestPart = item.FirstOrDefault().requestpart;
                this.fpSpread1.Sheets[0].Cells[row, 1].Value = RequestPart;

                //2번부터는 데이터를 넣어야 한다
                double sumOt = 0.0;
                //double holytime = 0.0;
                int coldata = 2;
                for (int i = 2; i < 82; i++)
                {
                    var colName = fpSpread1.Sheets[0].Cells[6, i].Value.ToString();

                    //이 이름에 해당하는 데이터의 시간을 가져온다
                    double ot = 0.0;
                    double hrs = 0.0;
                    if (colName != "*")
                    {
                        //double holytime = 0.0;
                        var timeList = item.Where(t => t.process == colName);
                        if (timeList != null)
                        {
                            hrs = (double)timeList.Sum(t => t.hrs);
                            ot = (double)timeList.Sum(t => t.ot);
                            sumOt += ot;
                        }
                    }
                    if (ot + hrs == 0.0) fpSpread1.Sheets[0].Cells[row, coldata].Value = null;
                    else fpSpread1.Sheets[0].Cells[row, coldata].Value = ot + hrs; //없음으로한다

                    coldata += 1;
                }

                //ETC영역계산
                {
                    //전체합산데이터와, 2~10까지의 데이터가 일치하지 않으면 그것이 ETC이다
                    var etchr = item.Sum(t => (float)t.hrs);
                    var etcot = item.Sum(t => (float)t.ot);

                    //현재데이터의  hrs의 합
                    var subtotal = 0f;
                    for (int i = 2; i < 82; i++)
                    {
                        var ivalue = fpSpread1.Sheets[0].Cells[row, i].Value;
                        if (ivalue != null)
                        {
                            subtotal = subtotal + float.Parse(ivalue.ToString());
                        }
                    }
                    var etcval = (etchr + etcot) - subtotal;
                    if (etcval != 0f)
                        Console.WriteLine("sdf");
                    fpSpread1.Sheets[0].Cells[row, 82].Value = etcval;
                }

                fpSpread1.Sheets[0].Cells[row, 83].CellType = numberCellType1;
                fpSpread1.Sheets[0].Cells[row, 83].ParseFormatString = "N1";
                fpSpread1.Sheets[0].Cells[row, 83].Formula = string.Format("SUM(C{0}:CD{0})+CE{0}", row + 1);
                fpSpread1.Sheets[0].Cells[row, 83].BackColor = Color.Gold;
                fpSpread1.Sheets[0].Cells[row, 83].Border = new ComplexBorder(left, top, right, bottom);
                fpSpread1.Sheets[0].Cells[row, 83].HorizontalAlignment = FarPoint.Win.Spread.CellHorizontalAlignment.Center;
                fpSpread1.Sheets[0].Cells[row, 83].VerticalAlignment = FarPoint.Win.Spread.CellVerticalAlignment.Center;

                //H8 /$I$4
                if (sumOt == 0.0) fpSpread1.Sheets[0].Cells[row, 84].Value = null; //OT합계
                else fpSpread1.Sheets[0].Cells[row, 84].Value = sumOt; //OT합계

                // process 의 휴가시간을 다시 계산한다.
                var 휴가데이터 = baseData.Where(t => t.requestpart == RequestPart && t.svalue == "휴가");
                if (휴가데이터 == null || 휴가데이터.Count() < 1)
                {
                    fpSpread1.Sheets[0].Cells[row, 85].Value = null;// 0.0; //휴가시간
                }
                else fpSpread1.Sheets[0].Cells[row, 85].Value = 휴가데이터.Sum(t => t.hrs); //휴가시간

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

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

                for (int i = 1; i <= 82; i++)
                {
                    if (i == 82) fpSpread1.Sheets[0].Cells[row, i].BackColor = Color.LightGray;
                    else fpSpread1.Sheets[0].Cells[row, i].BackColor = Color.White;
                    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;
                }


                row += 1;
                Application.DoEvents();
            }

            //합계데이터
            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 <= 82; i++)
            {
                char basec = 'C';
                char newc = (char)(basec + (i - 2));
                fpSpread1.Sheets[0].Cells[row, i].Formula = "SUM(" + ColumnAdress(i + 1) + "8:" + ColumnAdress(i + 1) + 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;
            }

            fpSpread1.Sheets[0].Cells[row, 83].CellType = numberCellType1;
            fpSpread1.Sheets[0].Cells[row, 83].ParseFormatString = "N1";
            fpSpread1.Sheets[0].Cells[row, 83].Formula = string.Format("SUM(C{0}:CD{0})+CE{0}", row + 1);
            fpSpread1.Sheets[0].Cells[row, 83].BackColor = Color.Gold;


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



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

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


            //포션값추가
            row += 1;
            this.fpSpread1.Sheets[0].RowCount = row + 1;


            //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;


            FarPoint.Win.Spread.CellType.PercentCellType pct = new FarPoint.Win.Spread.CellType.PercentCellType();
            //numberCellType1.NegativeRed = true;
            //numberCellType1.NullDisplay = "--";


            for (int i = 2; i <= 82; i++)
            {
                fpSpread1.Sheets[0].Cells[row, i].Formula = ColumnAdress(i + 1) + row.ToString() + "/" + "CF" + row.ToString();
                //fpSpread1.Sheets[0].Cells[row, i].BackColor = Color.LightGray;

                fpSpread1.Sheets[0].Cells[row, i].CellType = pct;
                //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;
            }

            //CI8데이터 추가
            //fpSpread1_Sheet1.ColumnCount += 1;
            for (int i = 8; i < row ; i++)
            {
                var cellname = "CI" + i.ToString();
                fpSpread1.Sheets[0].Cells[cellname].Formula = $"CF{i}/CF{row}";
                fpSpread1.Sheets[0].Cells[cellname].CellType = pct;
                fpSpread1.Sheets[0].Cells[cellname].Border = new ComplexBorder(left, top, right, bottom);
                fpSpread1.Sheets[0].Cells[cellname].HorizontalAlignment = FarPoint.Win.Spread.CellHorizontalAlignment.Center;
                fpSpread1.Sheets[0].Cells[cellname].VerticalAlignment = FarPoint.Win.Spread.CellVerticalAlignment.Center;
            }



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

            fpSpread1.Visible = true;

            //FCOMMON.Util.MsgI("조회 완료");

        }

        public string ColumnAdress(int col)
        {
            if (col <= 26)
            {
                return Convert.ToChar(col + 64).ToString();
            }
            int div = col / 26;
            int mod = col % 26;
            if (mod == 0) { mod = 26; div--; }
            return ColumnAdress(div) + ColumnAdress(mod);
        }


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

        private void btRefresh_Click(object sender, EventArgs e)
        {
            refrehData();
        }

        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);
            }
        }

        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            //이전달
            var sd = dts.Value.AddMonths(-1);
            var ed = sd.AddMonths(1);
            dts.Value = sd;
            dte.Value = ed;
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            //다음달
            var sd = dts.Value.AddMonths(1);
            var ed = sd.AddMonths(1);
            dts.Value = sd;
            dte.Value = ed;
        }
    }
}
