using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using util = FCOMMON.Util;

using NetOffice;
using Outlook = NetOffice.OutlookApi;
using NetOffice.OutlookApi.Enums;
using FEQ0000.Purchase;
using FCOMMON;
using NetOffice.OfficeApi;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using FarPoint.Win.Spread;
using System.Net.NetworkInformation;

namespace FEQ0000
{
    public partial class fPurchaseEB : FCOMMON.fBase
    {
        string fn_fpcolsize = "";

        public fPurchaseEB()
        {
            InitializeComponent();
            Properties.Settings.Default["gwcs"] = FCOMMON.info.CS;
            Properties.Settings.Default["EEEntities"] = FCOMMON.info.CS;

            fn_fpcolsize = util.MakeFilePath(util.CurrentPath, "formSetting", "fp_" + this.Name + ".ini");
            this.dsPurchase.EETGW_PurchaseEB.TableNewRow += Purchase_TableNewRow;
            this.FormClosing += FPurchase_FormClosing;
            this.FormClosed += __Closed;
            dtSD.KeyDown += dtSD_KeyDown;
            dtED.KeyDown += dtSD_KeyDown;
            //this.dv1.CellFormatting += dv1_CellFormatting;
        }

        private void FPurchase_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (dsPurchase.HasChanges())
            {
                var dlg = FCOMMON.Util.MsgQ("변경된 자료가 있습니다. 화면을 닫을까요? 닫으면 변경된 자료는 손실 됩니다");
                if (dlg != DialogResult.Yes)
                {
                    e.Cancel = true;
                    return;
                }
            }
        }

        void dtSD_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode != Keys.Enter) return;
            var tb = sender as ToolStripTextBox;
            var input = tb.Text.Trim();
            if (input == "") tb.Text = DateTime.Now.ToString("yyyy-MM-dd");
            else
            {
                string dt = string.Empty;
                if (!util.MakeDateString(input, out dt))
                {
                    FCOMMON.Util.MsgE("입력값이 올바르지 않습니다.");
                    tb.SelectAll();
                    tb.Focus();
                    return;
                }
                else
                {
                    tb.Text = dt;
                }
            }
            if (tb == dtSD)
            {
                dtED.Focus();
                dtED.SelectAll();
            }
            else
            {
                btSearch.PerformClick();
                tb.SelectAll();
            }
        }

        void __Closed(object sender, FormClosedEventArgs e)
        {

        }

        void Purchase_TableNewRow(object sender, DataTableNewRowEventArgs e)
        {
            e.Row["gcode"] = FCOMMON.info.Login.gcode;
            e.Row["pdate"] = DateTime.Now.ToString("yyyy-MM-dd");
            e.Row["wuid"] = FCOMMON.info.Login.no;
            e.Row["wdate"] = DateTime.Now;
            e.Row["pumunit"] = "EA";
            e.Row["state"] = "---";
            e.Row["pumqty"] = 0;
            e.Row["pumqtyreq"] = 0;
            e.Row["pumprice"] = 0;
            e.Row["pumamt"] = 0;
            e.Row["request"] = FCOMMON.info.Login.nameK;
            e.Row["receive"] = "";// FCOMMON.info.Login.nameK;
            e.Row["place"] = "전자실";
        }
        
        private void __Load(object sender, EventArgs e)
        {
            EnsureVisibleAndUsableSize();
            this.cmDate.SelectedIndex = 0;
            this.tbRequest.Text = string.Empty; //양진원 FCOMMON.info.Login.nameK;
            this.cmbSort.SelectedIndex = 0;
            this.dtSD.Text = DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd");
            this.dtED.Text = DateTime.Now.AddDays(10).ToString("yyyy-MM-dd");

            //state list
            var stList = FCOMMON.DBM.getCodeList("04");
            this.cmbState.Items.Clear();
            cmbState.Items.Add("-- 전체 --");
            foreach (var item in stList)
                cmbState.Items.Add(item.Value);
            cmbState.Items.Add("<Received");
            //cmbState.Items.Add("App+PR+PO");
            this.cmbState.SelectedIndex = 0;

            //all기본 - 양진원
            //this.cmbCr.SelectedIndex = 1;

            //일반사용자의경우에는 상태를 변경하지 못한다.
            int curLevel = Math.Max(FCOMMON.info.Login.level, FCOMMON.DBM.getAuth(FCOMMON.DBM.eAuthType.purchaseEB));
            if (curLevel >= 5)
            {
                btSave.Visible = true;
                엑셀에서가져오기ToolStripMenuItem.Enabled = true;
                상태일괄변경ToolStripMenuItem.Enabled = true;
            }
            else
            {
                btMakeItemsData.Visible = false;
                상태일괄변경ToolStripMenuItem.Enabled = false;
                엑셀에서가져오기ToolStripMenuItem.Enabled = false;
                btSave.Visible = false;
                btViewDel.Visible = false;
                fpSpread1.EditMode = false;
                fpSpread1.Sheets[0].SelectionUnit = FarPoint.Win.Spread.Model.SelectionUnit.Row;
                fpSpread1.EditModePermanent = false;
                fpSpread1.EditModeReplace = false;

                foreach (FarPoint.Win.Spread.Column col in fpSpread1.ActiveSheet.Columns)
                    col.Locked = true;
            }

            refreshData();

            //열표시여부를 설정
            var adv = FCOMMON.Util.getBit(FCOMMON.info.Login.gpermission, (int)FCOMMON.eGroupPermission.purchase_adv);
            if (adv == false)
            {
                var hidecols = new string[] { "receivename", "receive", "asset", "dept", "manuproc", "process", "cr", "orderno", "manuproc", "project", "projectidx", "edate", "po" };
                foreach (FarPoint.Win.Spread.Column col in fpSpread1_Sheet1.Columns)
                {
                    if (hidecols.Contains(col.DataField.ToLower())) col.Visible = false;
                }
            }
        }


        private void refreshData()
        {

            try
            {
                string state = "%";
                if (cmbState.SelectedIndex > 0) state = cmbState.Text.Split(',')[0];

                string request = "%";
                if (tbRequest.Text.Trim() != "")
                    request = "%" + tbRequest.Text.Trim() + "%";// tbRequest.Text.Substring(1, tbRequest.Text.IndexOf("]") - 1);


                string dateField = "pdate";
                if (cmDate.SelectedIndex == 1) dateField = "indate";
                else if (cmDate.SelectedIndex == 2) dateField = "expdate";


                System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter();
                System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
                cmd.CommandText = " select *,dbo.getusername(request) as requestName,dbo.getusername(receive) as receiveName" +
                                   " from EETGW_PurchaseEB with(nolock) " +
                                   " where gcode='" + FCOMMON.info.Login.gcode + "' and  isnull(" + dateField + ",'') between @sd and @ed ";

                if (btViewDel.Checked == false)
                    cmd.CommandText += " and isnull(isdel,0) = 0";


                if (tbRequest.Text.Trim() != "")
                {
                    cmd.CommandText += " and (isnull(dbo.getusername(request),'') like @req or isnull(dbo.getusername(receive),'') like @req)";
                }

                if (cmbState.SelectedIndex != 0)
                {
                    if (cmbState.Text.ToUpper() == "<RECEIVED")
                    {
                        cmd.CommandText += " and isnull([state],'') in ('','---','Approving','PR','PO')";
                    }
                    //else if(cmbState.Text.ToUpper() == "APP+PR+PO")
                    //{
                    //    cmd.CommandText += " and isnull([state],'') in ('','---','Approving','PR','PO')";
                    //}
                    else
                    {
                        cmd.CommandText += " and isnull([state],'') like @st";
                    }
                }

                if (cmbSort.SelectedIndex == 1)
                {
                    dateField = "edate";
                    cmd.CommandText += " ORDER BY " + dateField + " DESC, idx DESC";
                }
                else if (cmbSort.SelectedIndex == 2)
                {
                    dateField = "sc";
                    cmd.CommandText += " ORDER BY " + dateField + " DESC, idx DESC";
                }
                else if (cmbSort.SelectedIndex == 3)
                {
                    cmd.CommandText += " ORDER BY state , (case sid when '' then '0' when '신규' then '0' when '신규품목' then '0' else '1' end) desc, pdate desc, idx DESC";
                }
                else
                {
                    cmd.CommandText += " ORDER BY " + dateField + " DESC, idx DESC";
                }

                cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@sd", dtSD.Text));
                cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ed", dtED.Text));
                cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@req", request));
                cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@st", state));
                cmd.Connection = this.ta.Connection;
                da.SelectCommand = cmd;

                //read adata
                this.dsPurchase.EETGW_PurchaseEB.Clear();
                da.Fill(this.dsPurchase.EETGW_PurchaseEB);
                this.dsPurchase.AcceptChanges();
                showSummary();
                FCOMMON.Util.FPColSizeLoad(ref this.fpSpread1, fn_fpcolsize);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }

            FormattingData();
        }
        void FormattingData()
        {
            //삭제컬럼인덱스
            this.fpSpread1.SuspendLayout();
            var delindex = this.fpSpread1.ActiveSheet.Columns["isdel"].Index;
            var statindex = this.fpSpread1.ActiveSheet.Columns["state"].Index;
            var crcfindex = this.fpSpread1.ActiveSheet.Columns["crcf"].Index;
            var prjindex = this.fpSpread1.ActiveSheet.Columns["projectidx"].Index;
            var cstsindex = this.fpSpread1.ActiveSheet.Columns["conf_status"].Index;

            for (int i = 0; i < this.fpSpread1.ActiveSheet.Rows.Count; i++)
            {
                var state = this.fpSpread1.ActiveSheet.GetValue(i, statindex);
                string stateStr = string.Empty;
                if (state != null) stateStr = state.ToString();

                var value = this.fpSpread1.ActiveSheet.GetValue(i, delindex);
                var crcf = this.fpSpread1.ActiveSheet.GetValue(i, crcfindex);
                var v_confstats = this.fpSpread1.ActiveSheet.GetValue(i, cstsindex);

                var str_crcf = string.Empty;
                var str_confstats = string.Empty;
                if (crcf != null) str_crcf = crcf.ToString();
                if (v_confstats != null) str_confstats = v_confstats.ToString();

                if (value != null && (Boolean)value)
                {
                    this.fpSpread1.ActiveSheet.Rows[i].BackColor = Color.Red;
                    this.fpSpread1.ActiveSheet.Rows[i].ForeColor = Color.White;
                }
                else
                {
                    //crcf 에 따라서 배경색 변경
                    if (str_crcf != "")
                        this.fpSpread1.ActiveSheet.Rows[i].BackColor = Color.FromArgb(50, Color.PowderBlue);
                    else
                        this.fpSpread1.ActiveSheet.Rows[i].BackColor = Color.White;


                    switch (stateStr.ToLower())
                    {
                        case "cancled":
                            this.fpSpread1.ActiveSheet.Rows[i].ForeColor = Color.Red;
                            break;
                        case "rejected":
                            this.fpSpread1.ActiveSheet.Rows[i].ForeColor = Color.Tomato;
                            break;
                        case "spr":
                            this.fpSpread1.ActiveSheet.Rows[i].ForeColor = Color.Magenta;
                            break;
                        case "---":
                        case "----":
                            this.fpSpread1.ActiveSheet.Rows[i].ForeColor = Color.Blue;
                            break;
                        case "received":
                            this.fpSpread1.ActiveSheet.Rows[i].ForeColor = Color.Gray;
                            break;
                        case "hold":
                            this.fpSpread1.ActiveSheet.Rows[i].ForeColor = Color.HotPink;
                            break;
                        case "approving":
                            this.fpSpread1.ActiveSheet.Rows[i].ForeColor = Color.DarkGoldenrod;

                            if (str_confstats == "2")   //ok
                                this.fpSpread1.ActiveSheet.Rows[i].BackColor = Color.Lime;
                            else if (str_confstats == "3")  //reject
                                this.fpSpread1.ActiveSheet.Rows[i].BackColor = Color.HotPink;
                            break;
                        default:
                            this.fpSpread1.ActiveSheet.Rows[i].ForeColor = Color.Black;
                            break;
                    }
                }

                //프로젝트가 걸린데이터는 글자를 bold체로 변경한다.
                var prjdata = this.fpSpread1.ActiveSheet.GetValue(i, prjindex);
                if (prjdata != null)
                {
                    var pidx = (int)this.fpSpread1.ActiveSheet.GetValue(i, prjindex);
                    if (pidx == -1)  //프로젝트가 없다
                    {
                        this.fpSpread1.ActiveSheet.Rows[i].Font = fBase;
                    }
                    else
                    {
                        this.fpSpread1.ActiveSheet.Rows[i].Font = fBold;
                    }
                }
                else this.fpSpread1.ActiveSheet.Rows[i].Font = fBold;


            }
            this.fpSpread1.ResumeLayout();
        }

        Font fBase = new Font("맑은 고딕", 9);
        Font fBold = new Font("맑은 고딕", 9, FontStyle.Bold);

        private void saveData(Boolean prompt)
        {
            this.Validate();
            this.bs.EndEdit();

            try
            {
                var cnt = this.tam.UpdateAll(this.dsPurchase);
                if (prompt) FCOMMON.Util.MsgI(string.Format("{0}건의 자료가 저장 되었습니다.", cnt));
            }
            catch (Exception ex)
            {
                FCOMMON.Util.MsgE("저장 실패\n" + ex.Message);
            }
        }
        void showSummary()
        {
            decimal sum = 0;
            var list = this.dsPurchase.EETGW_PurchaseEB.Select(this.bs.Filter, "") as dsPurchase.EETGW_PurchaseEBRow[];
            sum = list.Sum(t => t.pumamt);
            //foreach (dsPurchase.PurchaseRow dr in this.dsPurchase.Purchase.Rows)
            //if (!dr.IspumamtNull()) sum += dr.pumamt;
            lbSum.Text = sum.ToString("N0");
        }

        private void btSearch_Click(object sender, EventArgs e)
        {
            refreshData();
        }

        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
            func_add();
        }

        private void tbRequest_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                btSearch.PerformClick();
        }

        private void btSave_Click(object sender, EventArgs e)
        {
            saveData(true);
        }


        private void lbEnd_Click(object sender, EventArgs e)
        {
            //end date
            var list = FCOMMON.DBM.getGroupList("pdate", "EETGW_purchaseEB", "pdate >= '" + dtSD.Text + "'", true);
            FCM0000.fLovOneItem f = new FCM0000.fLovOneItem(list);
            if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                dtED.Text = f.Title;
                btSearch.PerformClick();
            }
        }

        private void toolStripLabel3_Click(object sender, EventArgs e)
        {
            //사용자목록처리
            if (tbRequest.Text.Trim() == "")
            {
                tbRequest.Text = FCOMMON.info.Login.nameK;
            }
            else
            {
                tbRequest.Text = string.Empty;
            }

            refreshData();
        }

        private bool getAdminInput
        {
            get
            {
                return FCOMMON.Util.getBit(
                FCOMMON.info.Login.gpermission,
                (int)FCOMMON.eGroupPermission.purchase_adv);
            }
        }

        private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
        {
            func_delete();
        }
        void func_add()
        {
            var newdr = this.dsPurchase.EETGW_PurchaseEB.NewEETGW_PurchaseEBRow();

            if (FCOMMON.info.Login.no == "dev")
                newdr.request = "395552";//string.Format("[{0}] {1}", "395552", "김치균");
            else
                newdr.request = FCOMMON.info.Login.no;

            newdr.place = "전자실";

            var t1 = DBM.getCodeList("65");
            var t2 = DBM.getCodeList("66");
            if (t1.Count == 1)
                newdr.purchase_manager = t1.First().Value;
            if (t2.Count == 1)
                newdr.purchase_admin = t2.First().Value;

            repeat:

            bool repeat = false;
            DialogResult dlg;

            var f = new fPurchaseEB_Add(newdr);
            dlg = f.ShowDialog();
            repeat = f.repeatAdd;



            if (dlg == System.Windows.Forms.DialogResult.OK)
            {
                //존재하지 않는 sid 는 추가를 해준다.
                var newidx = AddItemInfoGetIndex(newdr);
                if (newidx != -1)
                {
                    newdr.pumidx = newidx;
                    newdr.EndEdit();
                }

                this.dsPurchase.EETGW_PurchaseEB.AddEETGW_PurchaseEBRow(newdr);

                int cnt = this.ta.Update(newdr);
                if (cnt == 1)
                {
                    if (repeat)
                    {
                        FCOMMON.Util.MsgI("저장 완료\n\n연속 저장 모드이므로 직전에 입력된 자료가 자동으로 설정 됩니다.");

                    }
                    else FCOMMON.Util.MsgI("저장 완료");
                }
                else
                {
                    FCOMMON.Util.MsgE("저장 실패\n\n다시 시도하시고 증상이 반복되면 chikyun.kim@amkor.co.kr 로 문의 주십시요");
                }


                newdr.AcceptChanges();
                if (repeat)
                {
                    var newdro = this.dsPurchase.EETGW_PurchaseEB.NewEETGW_PurchaseEBRow();
                    FCOMMON.Util.CopyData(newdr, newdro);
                    newdro.idx = -1;
                    newdro.wdate = DateTime.Now;
                    newdr = newdro; //change
                    goto repeat;
                }
                else refreshData(); //181210
            }
            else newdr.Delete();



        }
        void func_delete()
        {
            var drv = bs.Current as DataRowView;
            if (drv == null) return;

            int curLevel = Math.Max(FCOMMON.info.Login.level, FCOMMON.DBM.getAuth(FCOMMON.DBM.eAuthType.purchaseEB));
            var dr = drv.Row as dsPurchase.EETGW_PurchaseEBRow;//.PurchaseRow;
            if (dr.sc != "")
            {
                if (curLevel < 5)
                {
                    FCOMMON.Util.MsgE("일반 사용자는 SC값이 있는 자료를 삭제할 수 없습니다.");
                    return;
                }
            }

            if (dr.request != FCOMMON.info.Login.no)
            {
                if (curLevel < 5)
                {
                    FCOMMON.Util.MsgE("일반 사용자는 타인의 자료를 삭제할 수 없습니다.");
                    return;
                }
            }

            if (curLevel < 5)
            {
                var dlg = FCOMMON.Util.MsgQ("현재 선택된 자료를 삭제하시겠습니까?");
                if (dlg != System.Windows.Forms.DialogResult.Yes) return;
            }
            else
            {
                var dlg = FCOMMON.Util.MsgQ("현재 선택된 자료를 삭제하시겠습니까?\n저장 버튼을 눌러야 최종 삭제 됩니다");
                if (dlg != System.Windows.Forms.DialogResult.Yes) return;
            }

            bs.RemoveCurrent();

            //일반사용자는 데이터를 바로 삭제한다.
            if (curLevel < 5)
            {
                try
                {
                    int cnt = ta.Update(this.dsPurchase);
                    if (cnt != 1)
                        FCOMMON.Util.MsgE(cnt.ToString() + "건의 자료가 삭제되었습니다.");
                }
                catch (Exception ex)
                {
                    FCOMMON.Util.MsgE("delete error\n" + ex.Message);
                }
            }
        }

        private int AddItemInfoGetIndex(dsPurchase.EETGW_PurchaseEBRow newdr)
        {
            //이 시드가 아이템목록에 없다면 추가 하고 idx를 조회한 후 설정해준다.
            if (newdr.sid == "신규") return -1;
            int retval = -1;
            var sid = newdr.sid;
            var iteminfo = FCOMMON.DBM.getItemInfo(sid);
            if (iteminfo.idx < 0)
            {
                FCOMMON.Models.ItemModel newitem = new FCOMMON.Models.ItemModel();
                newitem.sid = newdr.sid;
                newitem.name = newdr.pumname;
                newitem.price = newdr.pumprice.ToString();
                newitem.model = newdr.pumscale;
                newitem.unit = newdr.pumunit;
                newitem.scale = 1f;
                newitem.supply = newdr.supply;
                newitem.supplyidx = newdr.supplyidx;
                retval = FCOMMON.DBM.addItemInfo(newitem);
            }
            return retval;
        }

        private void copyDataToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void btFind_Click(object sender, EventArgs e)
        {
            var search = tbFind.Text.Trim();
            search = search.Replace("*", "x");
            if (tbFind.Text != search) tbFind.Text = search;
            try
            {
                if (search.isEmpty())
                {
                    this.bs.Filter = "";
                    tbFind.BackColor = Color.White;
                }
                else
                {
                    search = search.Replace("'", "''");
                    string filter = "supply like ? or sid like ? or process like ? or orderno like ? or sc like ? or pumname like ? or pumscale like ? or project like ?";
                    filter = filter.Replace("?", "'%" + search + "%'");
                    this.bs.Filter = filter;
                    tbFind.BackColor = Color.Lime;
                }
                tbFind.SelectAll();
                tbFind.Focus();
                showSummary();
            }
            catch (Exception ex)
            {
                this.tbFind.BackColor = Color.Tomato;
                FCOMMON.Util.MsgE(ex.Message);
            }
        }

        private void tbFind_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter) btFind.PerformClick();
        }

        private void editDataToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Func_Edit();
        }
        void Func_Edit()
        {
            var drv = this.bs.Current as DataRowView;
            if (drv == null) return;
            var newdr = drv.Row as dsPurchase.EETGW_PurchaseEBRow;//.PurchaseRow;

            bool repeat = false;
            DialogResult dlg;

            var f = new fPurchaseEB_Add(newdr);
            dlg = f.ShowDialog();
            repeat = f.repeatAdd;

            if (dlg == System.Windows.Forms.DialogResult.OK)
            {
                //존재하지 않는 sid 는 추가를 해준다.
                var newidx = AddItemInfoGetIndex(newdr);
                if (newidx != -1)
                {
                    newdr.pumidx = newidx;
                    newdr.EndEdit();
                }
                if (newdr.RowState != DataRowState.Unchanged)
                {
                    this.ta.Update(newdr);
                    newdr.AcceptChanges();
                }
            }
            else newdr.RejectChanges();

        }

        private void autoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FCOMMON.Util.FPColSizeAuto(this.fpSpread1);
            //this.fpSpread1.ActiveSheet.DataAutoSizeColumns = true;

            //for (int i = 0; i < this.fpSpread1.ActiveSheet.Rows.Count; i++)
            //    this.fpSpread1.ActiveSheet.SetRowHeight(i, 25);
            //dv1.AutoResizeColumns();
        }

        private void resetToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (FarPoint.Win.Spread.Column col in this.fpSpread1.ActiveSheet.Columns)
            {
                col.Width = 100;
            }
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FCOMMON.Util.FPColsizeSave(this.fpSpread1, fn_fpcolsize);
        }

        private void loadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FCOMMON.Util.FPColSizeLoad(ref this.fpSpread1, fn_fpcolsize);
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            Func_Edit();
        }



        private void exportDataToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog sd = new SaveFileDialog();
            sd.Filter = "excel|*.xls";
            sd.FileName = "nrplist.xls";
            if (sd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                fpSpread1.SaveExcel(sd.FileName,
                    FarPoint.Excel.ExcelSaveFlags.SaveAsViewed
                    | FarPoint.Excel.ExcelSaveFlags.SaveAsFiltered
                    | FarPoint.Excel.ExcelSaveFlags.NoFormulas
                    | FarPoint.Excel.ExcelSaveFlags.SaveCustomColumnHeaders);
                var a = FCOMMON.Util.MsgQ("다음 파일이 생성 되었습니다.\n\n" + sd.FileName + "\n파일을 확인 할까요?");
                if (a == DialogResult.Yes)
                {
                    FCOMMON.Util.RunExplorer(sd.FileName);
                }
            }

        }

        private void 내가등록한자료ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            cmDate.SelectedIndex = 0;
            dtSD.Text = DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd");
            dtED.Text = DateTime.Now.ToString("yyyy-MM-dd");
            cmbState.SelectedIndex = 0;
            tbRequest.Text = FCOMMON.info.Login.nameK;
            refreshData();
        }

        private void 금일입고품목ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            cmDate.SelectedIndex = 1; //입고일
            dtSD.Text = DateTime.Now.ToString("yyyy-MM-dd");   //당일
            dtED.Text = DateTime.Now.ToString("yyyy-MM-dd");
            tbRequest.Text = string.Empty;
            refreshData();
        }

        private void 이번달자료ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            dtSD.Text = DateTime.Now.ToString("yyyy-MM") + "-01";
            dtED.Text = DateTime.Now.ToString("yyyy-MM-dd");
            tbRequest.Text = string.Empty;
            refreshData();
        }

        private void btViewDel_Click(object sender, EventArgs e)
        {
            refreshData();
        }


        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        void func_copy()
        {
            var drv = this.bs.Current as DataRowView;
            if (drv == null) return;
            var dr = drv.Row as dsPurchase.EETGW_PurchaseEBRow;

            //현재 데이터를 입력하여 신규 추가를 한다.
            var newdr = this.dsPurchase.EETGW_PurchaseEB.NewEETGW_PurchaseEBRow();
            FCOMMON.Util.CopyData((System.Data.DataRow)dr, (System.Data.DataRow)newdr);
            newdr.orderno = string.Empty; //CR값 복사 안하게  210823
            newdr.pdate = DateTime.Now.ToString("yyyy-MM-dd");
            newdr.wdate = DateTime.Now;
            newdr.wuid = FCOMMON.info.Login.no;
            newdr.state = "---";
            if (newdr.sid.Length != 9 && newdr.sid.StartsWith("10") == false)
                newdr.sid = string.Empty;

            newdr.bigo = string.Empty;
            newdr.bigo2 = string.Empty;
            newdr.chkremark = string.Empty;
            newdr.request = FCOMMON.info.Login.no;
            newdr.receive = "";// FCOMMON.info.Login.nameK;
            newdr.sc = string.Empty;
            newdr.po = string.Empty;
            newdr.indate = string.Empty;
            newdr.edate = string.Empty;
            newdr.pumqty = 0; //실구매수량은 제거
            newdr.chk2 = false;
            newdr.chk1 = false;
            newdr.SetpumqtyNull();
            newdr.idx = -1;
            newdr.EndEdit();

        repeat:

            bool repeat = false;
            DialogResult dlg;

            var f = new fPurchaseEB_Add(newdr);
            dlg = f.ShowDialog();
            repeat = f.repeatAdd;


            if (dlg == System.Windows.Forms.DialogResult.OK)
            {
                //존재하지 않는 sid 는 추가를 해준다.
                var newidx = AddItemInfoGetIndex(newdr);
                if (newidx != -1)
                {
                    newdr.pumidx = newidx;
                    newdr.EndEdit();
                }

                this.dsPurchase.EETGW_PurchaseEB.AddEETGW_PurchaseEBRow(newdr);
                this.ta.Update(newdr);
                newdr.AcceptChanges();

                if (repeat)
                {
                    var newdro = this.dsPurchase.EETGW_PurchaseEB.NewEETGW_PurchaseEBRow();
                    FCOMMON.Util.CopyData(newdr, newdro);
                    newdro.idx = -1;
                    newdro.wdate = DateTime.Now;
                    newdr = newdro; //change
                    goto repeat;
                }
            }
            else newdr.Delete();
        }

        private void toolStripButton1_Click_2(object sender, EventArgs e)
        {
            func_copy();
        }

        private void 집계표ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var f = new Purchase.rPurchaseEB();
            f.MdiParent = this.MdiParent;
            f.Show();
        }

        private void makeRepeatToolStripMenuItem_Click(object sender, EventArgs e)
        {
            func_copy();
        }

        private void 편집ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Func_Edit();
        }

        private void 삭제ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            func_delete();
        }

        private void 추가ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            func_add();
        }

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

        private void sC검색ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //sc
            var drv = this.bs.Current as DataRowView;
            if (drv == null) return;
            var newdr = drv.Row as dsPurchase.EETGW_PurchaseEBRow;
            if (newdr.sc.Trim() == "")
            {
                FCOMMON.Util.MsgE("SC값이 없습니다");
                return;
            }
            tbFind.Text = newdr.sc;
            btFind.PerformClick();
        }

        private void cRCF검색ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //crcf
            var drv = this.bs.Current as DataRowView;
            if (drv == null) return;
            var newdr = drv.Row as dsPurchase.EETGW_PurchaseEBRow;
            if (newdr.orderno.Trim() == "")
            {
                FCOMMON.Util.MsgE("CR/CF값이 없습니다");
                return;
            }
            tbFind.Text = newdr.orderno;
            btFind.PerformClick();
        }

        private void toolStripLabel2_Click(object sender, EventArgs e)
        {
            if (tbFind.Text != "")
            {
                tbFind.Text = "";
                btFind.PerformClick();
            }

        }


        private void bs_CurrentChanged(object sender, EventArgs e)
        {
            var drv = this.bs.Current as DataRowView;
            if (drv == null)
            {
                this.label1.Text = "데이터가 선택되지 않았습니다";
                return;
            }
            var dr = drv.Row as dsPurchase.EETGW_PurchaseEBRow;
            if (dr.project.isEmpty())
                this.label1.Text = $"비고:{dr.bigo.Replace("\r", "").Replace("\n", "")}";
            else
                this.label1.Text = $"프로젝트:{dr.project},비고:{dr.bigo.Replace("\r", "").Replace("\n", "")}";

            if (dr.IschkremarkNull() == false && dr.chkremark.Length > 0)
            {
                this.label2.Text = $"구매담당비고:{dr.chkremark}";
                this.label2.Visible = true;
            }
            else this.label2.Visible = false;
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {

        }


        List<string> ChangeMailAddress(List<string> userid)
        {
            var db = new DataClasses1DataContext();

            List<string> retval = new List<string>();
            foreach (var id in userid)
            {
                UInt32 userno;
                if (UInt32.TryParse(id, out userno) == true)
                {
                    var user = db.Users.Where(t => t.id == id).FirstOrDefault();
                    if (user != null)
                    {
                        var data = string.Format("{0}<{1}>", user.name, user.email);
                        if (retval.Contains(data) == false)
                            retval.Add(data);
                    }
                }
                else
                {
                    if (retval.Contains(id) == false)
                        retval.Add(id);
                }
            }
            return retval;
        }

        private void 구매승인양식ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //구매승인양식
            var f = new fPurchaseEBList(this.dsPurchase.EETGW_PurchaseEB);
            f.Show();
        }

        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            //선택된 줄의 데이터를 생성하낟.
            var drv = this.bs.Current as DataRowView;
            if (drv == null) return;
            var dr = drv.Row as dsPurchase.EETGW_PurchaseEBRow;
            string buffer = string.Format("{0}_{1}", dr.pumname.Replace("_", "-"), dr.pumscale.Replace("_", "-"), dr.dept.Replace("_", "-"), dr.manuproc.Replace("_", "-"), dr.asset.Replace("_", "-"));
            Clipboard.SetText(buffer);
            //FCOMMON.Util.MsgI("다음 데이터가 클립보드에 저장됨\n\n" + buffer);  190131
        }

        private void dtSD_DoubleClick(object sender, EventArgs e)
        {
            var tb = sender as ToolStripTextBox;
            var text = tb.Text.Trim();
            var dt = DateTime.Parse(text);
            var f = new FCOMMON.fSelectDay(dt);
            if (f.ShowDialog() == DialogResult.OK)
            {
                tb.Text = f.dtPick.SelectionStart.ToString("yyyy-MM-dd");

                var sd = DateTime.Parse(this.dtSD.Text);
                var ed = DateTime.Parse(this.dtED.Text);
                if (ed < sd) this.dtED.Text = sd.ToString("yyyy-MM-dd");
            }
        }

        private void 견적서폴더열기ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            var datapath = FCOMMON.DBM.getCodeSvalue("55", "02");
            if (datapath.isEmpty())
            {
                FCOMMON.Util.MsgE("견적서 기본폴더 공용코드 55-02 값을 입력하세요");
                return;
            }
            string path = System.IO.Path.Combine(datapath, DateTime.Now.Year.ToString("0000") + "년");// "\\\\k4fs3201n\\ee1t$\\1. 장비기술1파트\\24_Project & Overhaul 예산 사용 실적\\구매 견적서\\" + DateTime.Now.Year.ToString("0000") + "년";
            if (System.IO.Directory.Exists(path) == false)
                FCOMMON.Util.RunExplorer(datapath);
            else
                FCOMMON.Util.RunExplorer(path);
        }

        private void 엑셀에서가져오기ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var f = new fPurchase_excelimport(fPurchase_excelimport.eImporttype.EB);
            f.Show();
        }

        private void 입고품목메일전송ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }


        private void toolStripButton3_Click_1(object sender, EventArgs e)
        {
            var fn = System.IO.Path.Combine(FCOMMON.Util.CurrentPath, "PurcManual.pdf");
            if (System.IO.File.Exists(fn))
            {
                FCOMMON.Util.RunExplorer(fn);
            }
            else FCOMMON.Util.MsgE("설명서 파일(manual.pdf)이 없습니다. 개발자 문의 해주세요(chikyun.kim@amkor.co.kr)");
        }

        private void fpSpread1_EditModeOff(object sender, EventArgs e)
        {
            if (fpSpread1_Sheet1.Columns["pumqty"].Index == fpSpread1_Sheet1.ActiveColumnIndex)
            {
                var drv = this.bs.Current as DataRowView;
                var dr = drv.Row as dsPurchase.EETGW_PurchaseEBRow;
                dr.pumamt = dr.pumqty * dr.pumprice;
                dr.EndEdit();
            }
            else if (fpSpread1_Sheet1.Columns["pumprice"].Index == fpSpread1_Sheet1.ActiveColumnIndex)
            {
                var drv = this.bs.Current as DataRowView;
                var dr = drv.Row as dsPurchase.EETGW_PurchaseEBRow;
                dr.pumamt = dr.pumqty * dr.pumprice;
                dr.EndEdit();
            }
        }

        private void toolStripButton4_Click_1(object sender, EventArgs e)
        {
            func_ipgo();
        }
        void func_ipgo()
        {
            var drv = this.bs.Current as DataRowView;
            var dr = drv.Row as dsPurchase.EETGW_PurchaseEBRow;

            int curLevel = Math.Max(FCOMMON.info.Login.level, FCOMMON.DBM.getAuth(FCOMMON.DBM.eAuthType.purchaseEB));
            if (curLevel < 5)   //일반사용자 입고 여부
            {
                if (dr.state != "PO" && dr.state != "PR")
                {
                    FCOMMON.Util.MsgE("PR/PO 상태의 자료만 입고처리가 가능 합니다");
                    return;
                }
                if (dr.request != FCOMMON.info.Login.no)
                {
                    FCOMMON.Util.MsgE("타인의 자료는 입고 처리할 수 없습니다");
                    return;
                }
            }
            var f = new FEQ0000.Purchase.fPurchaseEB_Ipgo(dr.idx, string.Empty);
            if (f.ShowDialog() == DialogResult.OK)
            {
                refreshData();
            }
        }

        private void 입고ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            func_ipgo();
        }


        private void 엑셀에서열기ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var fn = DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xls";
            fn = System.IO.Path.Combine(FCOMMON.Util.CurrentPath, "temp", fn);
            var fi = new System.IO.FileInfo(fn);
            if (fi.Directory.Exists == false) fi.Directory.Create();

            fpSpread1.SaveExcel(fi.FullName,
                FarPoint.Excel.ExcelSaveFlags.SaveAsViewed
                | FarPoint.Excel.ExcelSaveFlags.SaveAsFiltered
                | FarPoint.Excel.ExcelSaveFlags.NoFormulas
                | FarPoint.Excel.ExcelSaveFlags.SaveCustomColumnHeaders
                );

            FCOMMON.Util.RunExplorer(fi.FullName);
        }

        private void fpSpread1_CellClick(object sender, FarPoint.Win.Spread.CellClickEventArgs e)
        {

        }

        private void columnSizeToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        List<dsPurchase.EETGW_PurchaseEBRow> GetDatarows(bool all = false)
        {
            List<dsPurchase.EETGW_PurchaseEBRow> rows = new List<dsPurchase.EETGW_PurchaseEBRow>();
            var idxcol = this.fpSpread1_Sheet1.Columns["idx"];
            var idxconf = this.fpSpread1_Sheet1.Columns["conf_status"];
            var idxstatus = this.fpSpread1_Sheet1.Columns["state"];

            if (all)
            {
                FarPoint.Win.Spread.HideRowFilter f = (FarPoint.Win.Spread.HideRowFilter)fpSpread1_Sheet1.RowFilter;
                int[] FRows = f.GetIntersectedFilteredInRows();
                if (FRows == null)
                {
                    var rowc = this.fpSpread1_Sheet1.RowCount;
                    var colc = this.fpSpread1_Sheet1.ColumnCount;
                    var drows = (dsPurchase.EETGW_PurchaseEBRow[])(this.dsPurchase.EETGW_PurchaseEB.Select(this.bs.Filter, this.bs.Sort));
                    foreach (var dr in drows)
                        rows.Add(dr);
                }
                else
                {
                    List<int> rowidxs = new List<int>();
                    foreach (int i in FRows)
                    {
                        var row = this.fpSpread1_Sheet1.Rows[i];
                        if (fpSpread1_Sheet1.IsRowBound(i))
                        {
                            rowidxs.Add(i);
                        }
                    }

                    //수집된데이터를 보내야한다.
                    //var idx = 0;
                    foreach (var i in rowidxs)
                    {
                        var rowidx = (int)fpSpread1.ActiveSheet.GetValue(i, idxcol.Index);
                        var row = this.dsPurchase.EETGW_PurchaseEB.Where(t => t.idx == rowidx).First();
                        rows.Add(row);
                    }
                    if (rows.Any() == false)
                    {
                        if (this.bs.Count > 0)
                        {
                            var drv = this.bs.Current as DataRowView;
                            rows.Add(drv.Row as dsPurchase.EETGW_PurchaseEBRow);
                        }
                    }
                }




            }
            else
            {
                //선택된 자료의 데이터를 추출한다.
                var selected = this.fpSpread1_Sheet1.GetSelections();   //선택된 개체확인
                List<int> rowidxs = new List<int>();
              
                foreach (var item in selected)
                {
                    for (int i = item.Row; i < item.Row + item.RowCount; i++)
                    {
                        if (rowidxs.Contains(i) == false)
                        {
                            if (fpSpread1_Sheet1.IsRowBound(i))
                            {
                                var confsta = fpSpread1.ActiveSheet.GetValue(i, idxconf.Index);
                                var state = fpSpread1.ActiveSheet.GetValue(i, idxstatus.Index);
                                //if (state != null && state.ToString() != "---")
                                //{
                                //    FCOMMON.Util.MsgE($"{i}번 줄의 데이터는 신규 요청데이터가 아닙니다");
                                //}
                                //else if (confsta != null && confsta.ToString() != "0")
                                //{
                                //    FCOMMON.Util.MsgE($"{i}번 줄의 데이터는 신청이 완료된 자료 입니다");
                                //}
                                //else 
                                rowidxs.Add(i);
                            }
                        }
                    }
                }

                //수집된데이터를 보내야한다.
                //var idx = 0;
                foreach (var i in rowidxs)
                {
                    var rowidx = (int)fpSpread1.ActiveSheet.GetValue(i, idxcol.Index);
                    var row = this.dsPurchase.EETGW_PurchaseEB.Where(t => t.idx == rowidx).First();
                    rows.Add(row);
                }
                if (rows.Any() == false)
                {
                    if (this.bs.Count > 0)
                    {
                        var drv = this.bs.Current as DataRowView;
                        rows.Add(drv.Row as dsPurchase.EETGW_PurchaseEBRow);
                    }
                }
            }

            return rows;

        }

        private void toolStripButton8_Click(object sender, EventArgs e)
        {
            //수집된데이터를 보내야한다.
            var rows = GetDatarows();

            //이자료를 승인요청창에 보낸다.
            if (rows.Any() == false)
            {
                FCOMMON.Util.MsgE("대상 데이터가 없습니다.");
                return;
            }
            var f = new fPurchaseEB_ConfRequest(rows);
            f.ShowDialog();
            FormattingData();

        }

        private void 현재목록메일전송ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 상태일괄변경ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            var selected = this.fpSpread1_Sheet1.GetSelections();   //선택된 개체확인
            List<int> rows = new List<int>();
            foreach (var item in selected)
            {
                for (int i = item.Row; i < item.Row + item.RowCount; i++)
                {
                    if (rows.Contains(i) == false)
                    {
                        if (fpSpread1_Sheet1.IsRowBound(i))
                        {
                            rows.Add(i);
                        }

                    }

                }
            }

            //이대상의 실제 데이터베이스 인덱스값을 생성해서 폼에 전송한다.
            var codlist = DBM.getCodeList("04");

            var f = new FEQ0000.Purchase.fBatchUpdate(rows);
            if (f.ShowDialog() != DialogResult.OK) return;

            var colstat = fpSpread1_Sheet1.Columns["state"];
            var value = f.cmbState.Text;

            foreach (var rowindex in rows)
            {
                fpSpread1_Sheet1.SetValue(rowindex, colstat.Index, value);
            }

            FCOMMON.Util.MsgI($"{rows.Count} 건의 자료가 변경되었습니다\n저장 버튼을 누르면 적용 됩니다\n취소하려면 새로고침을 누르세요");
        }

        private void 현재목록ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MailSendNoForm(true);
        }

        void MailSendNoForm(bool alldata, string cate = "")
        {
            var form_subject = "";
            var form_body = "";
            var form_to = "";
            var form_cc = "{요청}";
            var form_bcc = "";//f.tbBcc.Text.Trim();
            bool attachfile = true;
            bool attachlist = true;

            if (cate.isEmpty() == false)
            {
                var db = new DataClasses1DataContext();
                var dr = db.MailForm.Where(t => t.cate == cate).FirstOrDefault();
                var f = new Purchase.fMailForm(cate);
                if (f.ShowDialog() != DialogResult.OK) return;

                form_subject = f.tbSubject.Text.Trim();
                form_body = f.htmlEditor1.Html;
                form_to = f.tbTo.Text.Trim();
                form_cc = f.tbCC.Text.Trim();
                form_bcc = f.tbBcc.Text.Trim();
                attachfile = f.chkAttach.Checked;
                attachlist = f.chkList.Checked;
            }

            //현재표시데이터중에 수신자목록을 가져온다
            var drows = this.GetDatarows(alldata);
            var grp_req = drows.Where(t => t.request.isEmpty() == false).GroupBy(t => t.request).Select(t => t.FirstOrDefault().request).ToList();
            var grp_rec = drows.Where(t => t.receive.isEmpty() == false).GroupBy(t => t.receive).Select(t => t.FirstOrDefault().receive).ToList();


            List<string> tolist = new List<string>();   //최종받는사람
            List<string> cclist = new List<string>();
            List<string> bcclist = new List<string>();

            //받는사람
            if (form_to.Contains("{요청}") == true) tolist.AddRange(grp_req);
            if (form_to.Contains("{수령}") == true) tolist.AddRange(grp_rec);
            form_to = form_to.Replace("{요청}", "");
            form_to = form_to.Replace("{수령}", "");
            tolist.AddRange(form_to.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries));
            tolist = ChangeMailAddress(tolist);

            //참조
            if (form_cc.Contains("{요청}") == true) cclist.AddRange(grp_req);
            if (form_cc.Contains("{수령}") == true) cclist.AddRange(grp_rec);
            form_cc = form_cc.Replace("{요청}", "");
            form_cc = form_cc.Replace("{수령}", "");
            cclist.AddRange(form_cc.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries));
            cclist = ChangeMailAddress(cclist);

            //숨은참조
            if (form_bcc.Contains("{요청}") == true) bcclist.AddRange(grp_req);
            if (form_bcc.Contains("{수령}") == true) bcclist.AddRange(grp_rec);
            form_bcc = form_bcc.Replace("{요청}", "");
            form_bcc = form_bcc.Replace("{수령}", "");
            bcclist.AddRange(form_bcc.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries));
            bcclist = ChangeMailAddress(bcclist);

            var datestr = DateTime.Now.ToString("yyyy-MM-dd");
            if (dtSD.Text == dtED.Text) datestr = dtSD.Text;
            else datestr = dtSD.Text + "~" + dtED.Text;
            form_subject = form_subject.Replace("{DATE}", datestr);

            try
            {
                Outlook.Application outlookApplication = new Outlook.Application();
                var newMail = outlookApplication.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
                newMail.Display();
                newMail.Subject = form_subject; // this.tbSubject.Text.Trim(); // dr.title;
                newMail.To = string.Join(";", tolist.ToArray());
                newMail.CC = string.Join(";", cclist.ToArray());
                newMail.BCC = string.Join(";", bcclist.ToArray());
                string fn = "";
                if (attachfile)
                {
                    var fi = new System.IO.FileInfo(FCOMMON.Util.CurrentPath + "\\Export\\PurchaseNRI_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xls");
                    if (fi.Directory.Exists == false) fi.Directory.Create();
                    fn = fi.FullName;
                }

                var tabledata = UTIL_EQ0000.MakeDataTableToHTML(drows, fn);
                if (attachlist)
                {
                    form_body += "<br />" + tabledata;
                }

                if (fn.isEmpty() == false)
                    newMail.Attachments.Add(fn);

                //newMail.BodyFormat = OlBodyFormat.olFormatHTML;
                form_body = form_body.Replace("{DATE}", datestr);
                newMail.HTMLBody = form_body + newMail.HTMLBody; //
            }
            catch (Exception ex)
            {
                util.MsgE("전송실패\n\n" + ex.Message + "\n\n" +
                    "아웃룩의 설정이 정상인지 확인하세요");
            }
        }

        private void 현재목록입고양식ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MailSendNoForm(true, "PF");

        }

        private void 선택목록ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MailSendNoForm(false);
        }

        private void 선택목록입고양식ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MailSendNoForm(false, "PF");
        }

        private void toolStripMenuItem6_Click(object sender, EventArgs e)
        {
            var ta = new dsPurchaseTableAdapters.QueriesTableAdapter();
            var dlg = FCOMMON.Util.MsgQ("구매내역에서 품목정보를 생성합니다, 중복되는 sid는 업데이트 되지 않습니다\n" +
                "완료메시지 나올떄까지 기다려주세요");
            if (dlg != DialogResult.Yes) return;
            ta.PurchaseDataToItemsEB(FCOMMON.info.Login.gcode);
            FCOMMON.Util.MsgI("업데이트 완료");
        }
    }
}
