using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsFormsApp1.Account;
using WindowsFormsApp1.Convenience;
using WindowsFormsApp1.Delivery;
using WindowsFormsApp1.DLS;
using WindowsFormsApp1.Home;
using WindowsFormsApp1.Mac;
using WindowsFormsApp1.Work_log;
using WindowsFormsApp1.마크;

using System.IO;
using WindowsFormsApp1.회계;

namespace WindowsFormsApp1
{
    public partial class Main : Form
    {
        Email email = new Email();
        Helper_DB _DB = new Helper_DB();
        public string DB_User_Data;
        public string User;
        public string com_idx;
        
        public Main()
        {
            InitializeComponent();
        }

        public string User_Name { get; internal set; }

        private void Main_Load(object sender, EventArgs e)
        {
            this.Visible = false;   // 메인폼을 먼저 숨김

            login login = new login();

            if (DialogResult.OK == login.ShowDialog(this))
            {
                this.Visible = true;
            }
            else { this.Close(); }

            _DB.DBcon();
            DB_User_Data = _DB.DB_Search("User_Data", "id", User_Name);
            try
            {
                string[] result = DB_User_Data.Split('|');

                if (result[3] == null) { }
                else {
                    toolStripLabel1.Text = "이용자 : " + result[3];
                    User = result[3];
                }

                if (result[8] != "관리자") { 마스터ToolStripMenuItem.Visible = false; }

                com_idx = _DB.DB_Select_Search("`idx`", "Comp", "comp_name", result[5]);
                com_idx = com_idx.Replace("|", "");

                this.Text = "[ '" + com_idx + "' : " + result[5] + " - " + result[3] + "]";
            }
            catch { }
        }

        // 홈 탭 클릭이벤트
        private User_Infor User_Infor;
        private Home_User_manage home_User_Manage;
        private Transaction_manage Home_transaction_Manage;
        private Order_manage Home_order_Manage;
        private pw_change Home_pw_Change;
        private Book_infor_manage Home_book_Infor_Manage;
        private ledger_of_use Home_ledger_Of_Use;

        private void 사용자정보ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (User_Infor != null)
            {
                User_Infor.Focus();
            }
            else
            {
                User_Infor = new User_Infor(this);
                User_Infor.TopMost = true;
                User_Infor.FormClosed += (o, ea) => User_Infor = null;
                User_Infor.Show();
            }
            User_Infor.Show();
        }
        private void 사용자관리ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (home_User_Manage != null)
            {
                home_User_Manage.Focus();
            }
            else
            {
                home_User_Manage = new Home_User_manage(this);
                home_User_Manage.MdiParent = this;
                home_User_Manage.WindowState = FormWindowState.Maximized;
                home_User_Manage.FormClosed += (o, ea) => home_User_Manage = null;
                home_User_Manage.Show();
            }
        }
        private void 납품거래처관리ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Home_transaction_Manage != null)
            {
                Home_transaction_Manage.Focus();
            }
            else
            {
                Home_transaction_Manage = new Transaction_manage(this);
                Home_transaction_Manage.MdiParent = this;
                Home_transaction_Manage.WindowState = FormWindowState.Maximized;
                Home_transaction_Manage.FormClosed += (o, ea) => Home_transaction_Manage = null;
                Home_transaction_Manage.Show();
            }
        }
        private void 주문처관리ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Home_order_Manage != null)
            {
                Home_order_Manage.Focus();
            }
            else
            {
                Home_order_Manage = new Order_manage(this);
                Home_order_Manage.MdiParent = this;
                Home_order_Manage.WindowState = FormWindowState.Maximized;
                Home_order_Manage.FormClosed += (o, ea) => Home_order_Manage = null;
                Home_order_Manage.Show();
            }
        }

        private void 비밀번호변경ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Home_pw_Change != null)
            {
                Home_pw_Change.Focus();
            }
            else
            {
                Home_pw_Change = new pw_change(this);
                Home_pw_Change.MdiParent = this;
                Home_pw_Change.WindowState = FormWindowState.Maximized;
                Home_pw_Change.FormClosed += (o, ea) => Home_pw_Change = null;
                Home_pw_Change.Show();
            }
        }

        private void 도서정보관리ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Home_book_Infor_Manage != null)
            {
                Home_book_Infor_Manage.Focus();
            }
            else
            {
                Home_book_Infor_Manage = new Book_infor_manage();
                Home_book_Infor_Manage.FormClosed += (o, ea) => Home_book_Infor_Manage = null;
                Home_book_Infor_Manage.Show();
            }
            Home_book_Infor_Manage.Show();
        }

        private void 사용대장ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Home_ledger_Of_Use != null)
            {
                Home_ledger_Of_Use.Focus();
            }
            else
            {
                Home_ledger_Of_Use = new ledger_of_use(this);
                Home_ledger_Of_Use.MdiParent = this;
                Home_ledger_Of_Use.WindowState = FormWindowState.Maximized;
                Home_ledger_Of_Use.FormClosed += (o, ea) => Home_ledger_Of_Use = null;
                Home_ledger_Of_Use.Show();
            }
        }

        // 납품관리 탭 클릭 이벤트
        Commodity_registration Del_commodity_Registration;
        List_Lookup del_list_lookup;
        List_aggregation del_list_Aggregation;
        Order_input del_order_Input;
        Price_check del_price_Check;
        Estimate Del_estimate;
        Purchase Del_purchase;
        Input_Purchase_Return del_input_Purchase_Return;
        Input_Lookup_Stock del_input_Lookup_Stock;

        private void 물품등록ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Del_commodity_Registration != null)
            {
                Del_commodity_Registration.Focus();
            }
            else
            {
                Del_commodity_Registration = new Commodity_registration(this);
                Del_commodity_Registration.MdiParent = this;
                Del_commodity_Registration.WindowState = FormWindowState.Maximized;
                Del_commodity_Registration.FormClosed += (o, ea) => Del_commodity_Registration = null;
                Del_commodity_Registration.Show();
            }
        }

        private void 목록등록편의ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (del_list_lookup != null)
            {
                del_list_lookup.Focus();
            }
            else
            {
                del_list_lookup = new List_Lookup(this);
                del_list_lookup.MdiParent = this;
                del_list_lookup.WindowState = FormWindowState.Maximized;
                del_list_lookup.FormClosed += (o, ea) => del_list_lookup = null;
                del_list_lookup.Show();
            }
        }

        private void 목록집계ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (del_list_Aggregation != null)
            {
                del_list_Aggregation.Focus();
            }
            else
            {
                del_list_Aggregation = new List_aggregation(this);
                del_list_Aggregation.MdiParent = this;
                del_list_Aggregation.WindowState = FormWindowState.Maximized;
                del_list_Aggregation.FormClosed += (o, ea) => del_list_Aggregation = null;
                del_list_Aggregation.Show();
            }
        }

        private void 주문입력ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (del_order_Input != null)
            {
                del_order_Input.Focus();
            }
            else
            {
                del_order_Input = new Order_input(this);
                del_order_Input.MdiParent = this;
                del_order_Input.WindowState = FormWindowState.Maximized;
                del_order_Input.FormClosed += (o, ea) => del_order_Input = null;
                del_order_Input.Show();
            }
        }

        private void 예가조회ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (del_price_Check != null)
            {
                del_price_Check.Focus();
            }
            else
            {
                del_price_Check = new Price_check(this);
                del_price_Check.MdiParent = this;
                del_price_Check.WindowState = FormWindowState.Maximized;
                del_price_Check.FormClosed += (o, ea) => del_price_Check = null;
                del_price_Check.Show();
            }
        }

        private void 견적서ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Del_estimate != null)
            {
                Del_estimate.Focus();
            }
            else
            {
                Del_estimate = new Estimate(this);
                Del_estimate.MdiParent = this;
                Del_estimate.WindowState = FormWindowState.Maximized;
                Del_estimate.FormClosed += (o, ea) => Del_estimate = null;
                Del_estimate.Show();
            }
        }

        private void 매입ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Del_purchase != null)
            {
                Del_purchase.Focus();
            }
            else
            {
                Del_purchase = new Purchase(this);
                Del_purchase.MdiParent = this;
                Del_purchase.WindowState = FormWindowState.Maximized;
                Del_purchase.FormClosed += (o, ea) => Del_purchase = null;
                Del_purchase.Show();
            }
        }

        private void 매입반품입력ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (del_input_Purchase_Return != null)
            {
                del_input_Purchase_Return.Focus();
            }
            else
            {
                del_input_Purchase_Return = new Input_Purchase_Return(this);
                del_input_Purchase_Return.MdiParent = this;
                del_input_Purchase_Return.WindowState = FormWindowState.Maximized;
                del_input_Purchase_Return.FormClosed += (o, ea) => del_input_Purchase_Return = null;
                del_input_Purchase_Return.Show();
            }
        }

        private void 재고입력및조회ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (del_input_Lookup_Stock != null)
            {
                del_input_Lookup_Stock.Focus();
            }
            else
            {
                del_input_Lookup_Stock = new Input_Lookup_Stock(this);
                del_input_Lookup_Stock.MdiParent = this;
                del_input_Lookup_Stock.WindowState = FormWindowState.Maximized;
                del_input_Lookup_Stock.FormClosed += (o, ea) => del_input_Lookup_Stock = null;
                del_input_Lookup_Stock.Show();
            }
        }

        // 회계 탭 클릭 이벤트
        Remit_reg2 Acc_remit_Reg2;
        Purchase_Input Acc_purchase_Input;
        Remit_reg Acc_remit_Reg;
        Purchase_Book Acc_purchase_Book;
        Purchase_Aggregation Acc_purchase_Aggregation;
        Purchase_not_pay Acc_purchase_Not_Pay;
        Sales_Input Acc_sales_Input;
        Sales_In_Pay Acc_sales_In_Pay;
        Sales_Deposit Acc_sales_Deposit;
        Sales_Book Acc_sales_Book;
        Sales_Not_Pay Acc_sales_Not_Pay;
        Bill_manage Acc_bill_Manage;


        private void 송금등록ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Acc_remit_Reg2 != null)
            {
                Acc_remit_Reg2.Focus();
            }
            else
            {
                Acc_remit_Reg2 = new Remit_reg2(this);
                // Acc_remit_Reg2.MdiParent = this;
                Acc_remit_Reg2.FormClosed += (o, ea) => Acc_remit_Reg2 = null;
                Acc_remit_Reg2.Show();
            }
        }
        private void 송금내역조회ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Acc_remit_Reg != null)
            {
                Acc_remit_Reg.Focus();
            }
            else
            {
                Acc_remit_Reg = new Remit_reg(this);
                Acc_remit_Reg.MdiParent = this;
                Acc_remit_Reg.WindowState = FormWindowState.Maximized;
                Acc_remit_Reg.FormClosed += (o, ea) => Acc_remit_Reg = null;
                Acc_remit_Reg.Show();
            }
        }

        private void 매입장부ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (Acc_purchase_Book != null)
            {
                Acc_purchase_Book.Focus();
            }
            else
            {
                Acc_purchase_Book = new Purchase_Book(this);
                Acc_purchase_Book.MdiParent = this;
                Acc_purchase_Book.WindowState = FormWindowState.Maximized;
                Acc_purchase_Book.FormClosed += (o, ea) => Acc_purchase_Book = null;
                Acc_purchase_Book.Show();
            }
        }

        private void 매입집계ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Acc_purchase_Aggregation != null)
            {
                Acc_purchase_Aggregation.Focus();
            }
            else
            {
                Acc_purchase_Aggregation = new Purchase_Aggregation(this);
                Acc_purchase_Aggregation.MdiParent = this;
                Acc_purchase_Aggregation.WindowState = FormWindowState.Maximized;
                Acc_purchase_Aggregation.FormClosed += (o, ea) => Acc_purchase_Aggregation = null;
                Acc_purchase_Aggregation.Show();
            }
        }
        
        private void 매입미결제ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Acc_purchase_Not_Pay != null)
            {
                Acc_purchase_Not_Pay.Focus();
            }
            else
            {
                Acc_purchase_Not_Pay = new Purchase_not_pay(this);
                Acc_purchase_Not_Pay.MdiParent = this;
                Acc_purchase_Not_Pay.WindowState = FormWindowState.Maximized;
                Acc_purchase_Not_Pay.FormClosed += (o, ea) => Acc_purchase_Not_Pay = null;
                Acc_purchase_Not_Pay.Show();
            }
        }
        
        private void 매출입력ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (Acc_sales_Input != null)
            {
                Acc_sales_Input.Focus();
            }
            else
            {
                Acc_sales_Input = new Sales_Input(this);
                Acc_sales_Input.MdiParent = this;
                Acc_sales_Input.WindowState = FormWindowState.Maximized;
                Acc_sales_Input.FormClosed += (o, ea) => Acc_sales_Input = null;
                Acc_sales_Input.Show();
            }
        }
        private void 매출입금toolStripMenuItem1_Click_1(object sender, EventArgs e)
        {
            if (Acc_sales_In_Pay != null)
            {
                Acc_sales_In_Pay.Focus();
            }
            else
            {
                Acc_sales_In_Pay = new Sales_In_Pay(this);
                Acc_sales_In_Pay.FormClosed += (o, ea) => Acc_sales_In_Pay = null;
                Acc_sales_In_Pay.Show();
            }
        }
        private void 매출입금ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (Acc_sales_Deposit != null)
            {
                Acc_sales_Deposit.Focus();
            }
            else
            {
                Acc_sales_Deposit = new Sales_Deposit(this);
                Acc_sales_Deposit.MdiParent = this;
                Acc_sales_Deposit.WindowState = FormWindowState.Maximized;
                Acc_sales_Deposit.FormClosed += (o, ea) => Acc_sales_Deposit = null;
                Acc_sales_Deposit.Show();
            }
        }

        private void 매출장부ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Acc_sales_Book != null)
            {
                Acc_sales_Book.Focus();
            }
            else
            {
                Acc_sales_Book = new Sales_Book(this);
                Acc_sales_Book.MdiParent = this;
                Acc_sales_Book.WindowState = FormWindowState.Maximized;
                Acc_sales_Book.FormClosed += (o, ea) => Acc_sales_Book = null;
                Acc_sales_Book.Show();
            }
        }

        private void 매출미수금ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Acc_sales_Not_Pay != null)
            {
                Acc_sales_Not_Pay.Focus();
            }
            else
            {
                Acc_sales_Not_Pay = new Sales_Not_Pay(this);
                Acc_sales_Not_Pay.MdiParent = this;
                Acc_sales_Not_Pay.WindowState = FormWindowState.Maximized;
                Acc_sales_Not_Pay.FormClosed += (o, ea) => Acc_sales_Not_Pay = null;
                Acc_sales_Not_Pay.Show();
            }
        }

        private void 매출입금ToolStripMenuItem_Click(object sender, EventArgs e)        // 계산서 관리
        {
            if (Acc_bill_Manage != null)
            {
                Acc_bill_Manage.Focus();
            }
            else
            {
                Acc_bill_Manage = new Bill_manage(this);
                Acc_bill_Manage.MdiParent = this;
                Acc_bill_Manage.WindowState = FormWindowState.Maximized;
                Acc_bill_Manage.FormClosed += (o, ea) => Acc_bill_Manage = null;
                Acc_bill_Manage.Show();
            }
        }

        //  마크 탭 이벤트
        Setup_Shortcut Mac_shortcut;
        Set_Macro Mac_set_Macro;
        Nonverbal Mac_nonverbal;
        Job_Order Job_Order;
        Mac_List Mac_List;
        Mac_Stat Mac_Stat;
        Make_Excel Excel_make;
        Search_Infor Mac_search_Infor;
        Check_ISBN Mac_check_ISBN;
        Mac_Input Mac_Input;
        Mac_Output Mac_Output;
        Check_copy Mac_check_Copy;
        DLS_Copy Mac_dLS_Copy;
        All_Book_manage Mac_all_Book_Manage;
        Mac_Chack_Up Mac_Chack_Up;
        Collect_Mac Mac_Collect;
        Symbol_Add Mac_symbol_Add;
        Equip_manage Mac_equip_Manage;
        Make_Document Make_Document;
        School_Lookup DLS_school_Lookup;
        Input_DLS DLS_input;

        private void 단축키설정ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Mac_shortcut != null)
            {
                Mac_shortcut.Focus();
            }
            else
            {
                Mac_shortcut = new Setup_Shortcut(this);
                Mac_shortcut.MdiParent = this;
                Mac_shortcut.WindowState = FormWindowState.Maximized;
                Mac_shortcut.FormClosed += (o, ea) => Mac_shortcut = null;
                Mac_shortcut.Show();
            }
        }
        private void 매크로문구설정ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Mac_set_Macro != null)
            {
                Mac_set_Macro.Focus();
            }
            else
            {
                Mac_set_Macro = new Set_Macro(this);
                Mac_set_Macro.MdiParent = this;
                Mac_set_Macro.WindowState = FormWindowState.Maximized;
                Mac_set_Macro.FormClosed += (o, ea) => Mac_set_Macro = null;
                Mac_set_Macro.Show();
            }
        }
        private void 불용어ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Mac_nonverbal != null)
            {
                Mac_nonverbal.Focus();
            }
            else
            {
                Mac_nonverbal = new Nonverbal(this);
                Mac_nonverbal.MdiParent = this;
                Mac_nonverbal.WindowState = FormWindowState.Maximized;
                Mac_nonverbal.FormClosed += (o, ea) => Mac_nonverbal = null;
                Mac_nonverbal.Show();
            }
        }
        private void 작업지시서ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Job_Order != null)
            {
                Job_Order.Focus();
            }
            else
            {
                Job_Order = new Job_Order(this);
                Job_Order.MdiParent = this;
                Job_Order.WindowState = FormWindowState.Maximized;
                Job_Order.FormClosed += (o, ea) => Job_Order = null;
                Job_Order.Show();
            }
        }

        private void 마크목록ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Mac_List != null)
            {
                Mac_List.Focus();
            }
            else
            {
                Mac_List = new Mac_List(this);
                Mac_List.MdiParent = this;
                Mac_List.WindowState = FormWindowState.Maximized;
                Mac_List.FormClosed += (o, ea) => Mac_List = null;
                Mac_List.Show();
            }
        }
        private void 소장자료검색ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Mac_search_Infor != null)
            {
                Mac_search_Infor.Focus();
            }
            else
            {
                Mac_search_Infor = new Search_Infor(this);
                Mac_search_Infor.MdiParent = this;
                Mac_search_Infor.WindowState = FormWindowState.Maximized;
                Mac_search_Infor.FormClosed += (o, ea) => Mac_search_Infor = null;
                Mac_search_Infor.Show();
            }
        }
        private void 엑셀작성ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Excel_make != null)
            {
                Excel_make.Focus();
            }
            else
            {
                Excel_make = new Make_Excel(this);
                Excel_make.MdiParent = this;
                Excel_make.WindowState = FormWindowState.Maximized;
                Excel_make.FormClosed += (o, ea) => Excel_make = null;
                Excel_make.Show();
            }
        }
        private void iSBN조회ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Mac_check_ISBN != null)
            {
                Mac_check_ISBN.Focus();
            }
            else
            {
                Mac_check_ISBN = new Check_ISBN(this);
                Mac_check_ISBN.MdiParent = this;
                Mac_check_ISBN.WindowState = FormWindowState.Maximized;
                Mac_check_ISBN.FormClosed += (o, ea) => Mac_check_ISBN = null;
                Mac_check_ISBN.Show();
            }
        }
        private void 반입ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Mac_Input != null)
            {
                Mac_Input.Focus();
            }
            else
            {
                Mac_Input = new Mac_Input(this);
                Mac_Input.MdiParent = this;
                Mac_Input.WindowState = FormWindowState.Maximized;
                Mac_Input.FormClosed += (o, ea) => Mac_Input = null;
                Mac_Input.Show();
            }
        }
        private void 반출ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Mac_Output != null)
            {
                Mac_Output.Focus();
            }
            else
            {
                Mac_Output = new Mac_Output(this);
                Mac_Output.MdiParent = this;
                Mac_Output.WindowState = FormWindowState.Maximized;
                Mac_Output.FormClosed += (o, ea) => Mac_Output = null;
                Mac_Output.Show();
            }
        }
        private void 복본조사ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (Mac_check_Copy != null)
            {
                Mac_check_Copy.Focus();
            }
            else
            {
                Mac_check_Copy = new Check_copy(this);
                Mac_check_Copy.MdiParent = this;
                Mac_check_Copy.WindowState = FormWindowState.Maximized;
                Mac_check_Copy.FormClosed += (o, ea) => Mac_check_Copy = null;
                Mac_check_Copy.Show();
            }
        }
        private void dLS복본조사ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Mac_dLS_Copy != null)
            {
                Mac_dLS_Copy.Focus();
            }
            else
            {
                Mac_dLS_Copy = new DLS_Copy(this);
                Mac_dLS_Copy.MdiParent = this;
                Mac_dLS_Copy.WindowState = FormWindowState.Maximized;
                Mac_dLS_Copy.FormClosed += (o, ea) => Mac_dLS_Copy = null;
                Mac_dLS_Copy.Show();
            }
        }

        private void 마크수집ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Mac_Collect != null)
            {
                Mac_Collect.Focus();
            }
            else
            {
                Mac_Collect = new Collect_Mac(this);
                Mac_Collect.MdiParent = this;
                Mac_Collect.WindowState = FormWindowState.Maximized;
                Mac_Collect.FormClosed += (o, ea) => Mac_Collect = null;
                Mac_Collect.Show();
            }
        }
        private void 전집관리ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (Mac_all_Book_Manage != null)
            {
                Mac_all_Book_Manage.Focus();
            }
            else
            {
                Mac_all_Book_Manage = new All_Book_manage(this);
                Mac_all_Book_Manage.MdiParent = this;
                Mac_all_Book_Manage.WindowState = FormWindowState.Maximized;
                Mac_all_Book_Manage.FormClosed += (o, ea) => Mac_all_Book_Manage = null;
                Mac_all_Book_Manage.Show();
            }
        }
        private void 검수ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Mac_Chack_Up != null)
            {
                Mac_Chack_Up.Focus();
            }
            else
            {
                Mac_Chack_Up = new Mac_Chack_Up(this);
                Mac_Chack_Up.MdiParent = this;
                Mac_Chack_Up.WindowState = FormWindowState.Maximized;
                Mac_Chack_Up.FormClosed += (o, ea) => Mac_Chack_Up = null;
                Mac_Chack_Up.Show();
            }
        }
        private void 저자기호ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Mac_symbol_Add != null)
            {
                Mac_symbol_Add.Focus();
            }
            else
            {
                Mac_symbol_Add = new Symbol_Add(this);
                Mac_symbol_Add.MdiParent = this;
                Mac_symbol_Add.WindowState = FormWindowState.Maximized;
                Mac_symbol_Add.FormClosed += (o, ea) => Mac_symbol_Add = null;
                Mac_symbol_Add.Show();
            }
        }

        private void dLS조회ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (DLS_school_Lookup != null)
            {
                DLS_school_Lookup.Focus();
            }
            else
            {
                DLS_school_Lookup = new School_Lookup(this);
                DLS_school_Lookup.MdiParent = this;
                DLS_school_Lookup.WindowState = FormWindowState.Maximized;
                DLS_school_Lookup.FormClosed += (o, ea) => DLS_school_Lookup = null;
                DLS_school_Lookup.Show();
            }
        }
        private void dLS입력ToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            if (DLS_input != null)
            {
                DLS_input.Focus();
            }
            else
            {
                DLS_input = new Input_DLS(this);
                DLS_input.MdiParent = this;
                DLS_input.WindowState = FormWindowState.Maximized;
                DLS_input.FormClosed += (o, ea) => DLS_input = null;
                DLS_input.Show();
            }
        }

        private void 서류작성ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Make_Document != null)
            {
                Make_Document.Focus();
            }
            else
            {
                Make_Document = new Make_Document(this);
                Make_Document.MdiParent = this;
                Make_Document.WindowState = FormWindowState.Maximized;
                Make_Document.FormClosed += (o, ea) => Make_Document = null;
                Make_Document.Show();
            }
        }
        private void 마크통계ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Mac_Stat != null)
            {
                Mac_Stat.Focus();
            }
            else
            {
                Mac_Stat = new Mac_Stat(this);
                Mac_Stat.MdiParent = this;
                Mac_Stat.WindowState = FormWindowState.Maximized;
                Mac_Stat.FormClosed += (o, ea) => Mac_Stat = null;
                Mac_Stat.Show();
            }
        }
        private void 장비관리ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (Mac_equip_Manage != null)
            {
                Mac_equip_Manage.Focus();
            }
            else
            {
                Mac_equip_Manage = new Equip_manage(this);
                Mac_equip_Manage.MdiParent = this;
                Mac_equip_Manage.WindowState = FormWindowState.Maximized;
                Mac_equip_Manage.FormClosed += (o, ea) => Mac_equip_Manage = null;
                Mac_equip_Manage.Show();
            }
        }

        //  작업일지 탭 이벤트
        Work_Log work_Log;

        private void 작업일지ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (work_Log != null)
            {
                work_Log.Focus();
            }
            else
            {
                work_Log = new Work_Log(this);
                work_Log.MdiParent = this;
                work_Log.WindowState = FormWindowState.Maximized;
                work_Log.FormClosed += (o, ea) => work_Log = null;
                work_Log.Show();
            }
        }

        //  편의기능 탭 이벤트
        Calendar calendar;
        Talk talk;
        Quick_menu quick_Menu;
        Board board;
        Send_Notice send_Notice;
        Sale_Sale sale_Sale;
        Sale_Settlement sale_Settlement;
        Sale_End sale_End;
        Sale_Member_Manage sale_Member_Manage;

        private void 캘린더ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (calendar != null)
            {
                calendar.Focus();
            }
            else
            {
                calendar = new Calendar(this);
                calendar.MdiParent = this;
                calendar.WindowState = FormWindowState.Maximized;
                calendar.FormClosed += (o, ea) => calendar = null;
                calendar.Show();
            }
        }
        private void 채팅ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (talk != null)
            {
                talk.Focus();
            }
            else
            {
                talk = new Talk(this);
                talk.MdiParent = this;
                talk.WindowState = FormWindowState.Maximized;
                talk.FormClosed += (o, ea) => talk = null;
                talk.Show();
            }
        }
        private void 퀵메뉴ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (quick_Menu != null)
            {
                quick_Menu.Focus();
            }
            else
            {
                quick_Menu = new Quick_menu(this);
                quick_Menu.MdiParent = this;
                quick_Menu.WindowState = FormWindowState.Maximized;
                quick_Menu.FormClosed += (o, ea) => quick_Menu = null;
                quick_Menu.Show();
            }
        }
        private void 게시판ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (board != null)
            {
                board.Focus();
            }
            else
            {
                board = new Board(this);
                board.MdiParent = this;
                board.WindowState = FormWindowState.Maximized;
                board.FormClosed += (o, ea) => board = null;
                board.Show();
            }
        }
        private void 공지발송ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (send_Notice != null)
            {
                send_Notice.Focus();
            }
            else
            {
                send_Notice = new Send_Notice(this);
                send_Notice.MdiParent = this;
                send_Notice.WindowState = FormWindowState.Maximized;
                send_Notice.FormClosed += (o, ea) => send_Notice = null;
                send_Notice.Show();
            }
        }
        private void 판매ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (sale_Sale != null)
            {
                sale_Sale.Focus();
            }
            else
            {
                sale_Sale = new Sale_Sale(this);
                sale_Sale.MdiParent = this;
                sale_Sale.WindowState = FormWindowState.Maximized;
                sale_Sale.FormClosed += (o, ea) => sale_Sale = null;
                sale_Sale.Show();
            }
        }
        private void 정산ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (sale_Settlement != null)
            {
                sale_Settlement.Focus();
            }
            else
            {
                sale_Settlement = new Sale_Settlement(this);
                sale_Settlement.MdiParent = this;
                sale_Settlement.WindowState = FormWindowState.Maximized;
                sale_Settlement.FormClosed += (o, ea) => sale_Settlement = null;
                sale_Settlement.Show();
            }
        }
        private void 판매마감ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (sale_End != null)
            {
                sale_End.Focus();
            }
            else
            {
                sale_End = new Sale_End(this);
                sale_End.MdiParent = this;
                sale_End.WindowState = FormWindowState.Maximized;
                sale_End.FormClosed += (o, ea) => sale_End = null;
                sale_End.Show();
            }
        }
        private void 회원관리ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (sale_Member_Manage != null)
            {
                sale_Member_Manage.Focus();
            }
            else
            {
                sale_Member_Manage = new Sale_Member_Manage(this);
                sale_Member_Manage.MdiParent = this;
                sale_Member_Manage.WindowState = FormWindowState.Maximized;
                sale_Member_Manage.FormClosed += (o, ea) => sale_Member_Manage = null;
                sale_Member_Manage.Show();
            }
        }

        //  마스터 탭 이벤트
        User_manage master_user_Manage;
        Notice_Send master_notice_Send;
        Sales_Details master_sales_Details;
        User_account_inquiry master_user_Account_Inquiry;
        Mac_Setting master_mac_setting;
        Batch_processing master_batch_Processing;

        private void 이용자관리ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (master_user_Manage != null)
            {
                master_user_Manage.Focus();
            }
            else
            {
                master_user_Manage = new User_manage(this);
                master_user_Manage.MdiParent = this;
                master_user_Manage.WindowState = FormWindowState.Maximized;
                master_user_Manage.FormClosed += (o, ea) => master_user_Manage = null;
                master_user_Manage.Show();
            }
        }
        private void 공지발송ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (master_notice_Send != null)
            {
                master_notice_Send.Focus();
            }
            else
            {
                master_notice_Send = new Notice_Send(this);
                master_notice_Send.MdiParent = this;
                master_notice_Send.WindowState = FormWindowState.Maximized;
                master_notice_Send.FormClosed += (o, ea) => master_notice_Send = null;
                master_notice_Send.Show();
            }
        }
        private void 매출내역ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (master_sales_Details != null)
            {
                master_sales_Details.Focus();
            }
            else
            {
                master_sales_Details = new Sales_Details(this);
                master_sales_Details.MdiParent = this;
                master_sales_Details.WindowState = FormWindowState.Maximized;
                master_sales_Details.FormClosed += (o, ea) => master_sales_Details = null;
                master_sales_Details.Show();
            }
        }
        private void 이용자거래처조회ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (master_user_Account_Inquiry != null)
            {
                master_user_Account_Inquiry.Focus();
            }
            else
            {
                master_user_Account_Inquiry = new User_account_inquiry(this);
                master_user_Account_Inquiry.MdiParent = this;
                master_user_Account_Inquiry.WindowState = FormWindowState.Maximized;
                master_user_Account_Inquiry.FormClosed += (o, ea) => master_user_Account_Inquiry = null;
                master_user_Account_Inquiry.Show();
            }
        }
        private void 마크설정ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (master_mac_setting != null)
            {
                master_mac_setting.Focus();
            }
            else
            {
                master_mac_setting = new Mac_Setting(this);
                master_mac_setting.MdiParent = this;
                master_mac_setting.WindowState = FormWindowState.Maximized;
                master_mac_setting.FormClosed += (o, ea) => master_mac_setting = null;
                master_mac_setting.Show();
            }
        }
        private void 일괄처리관리ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (master_batch_Processing != null)
            {
                master_batch_Processing.Focus();
            }
            else
            {
                master_batch_Processing = new Batch_processing(this);
                master_batch_Processing.MdiParent = this;
                master_batch_Processing.WindowState = FormWindowState.Maximized;
                master_batch_Processing.FormClosed += (o, ea) => master_batch_Processing = null;
                master_batch_Processing.Show();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // 엑셀 테스트
            Excel_text et = new Excel_text();
//            et.mk_Excel_Order();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ExcelTest.Marc marc = new ExcelTest.Marc();
            marc.Show();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            /*
            string FilePath = string.Empty;
            string filename = string.Empty;

            OpenFileDialog Odig = openFileDialog1;
            Odig.Filter = "Excel Files(*.xls)|*.xls|Excel Files(*.xlsx)|*.xlsx|All FIles(*.*)|*.*";
            Odig.Title = "엑셀파일을 선택해주세요.";
            
            if (Odig.ShowDialog() == DialogResult.OK)
            {
                FilePath = Odig.FileName;
                filename = Path.GetFileName(FilePath);
                FilePath = Path.GetDirectoryName(FilePath);
                if (Path.GetExtension(filename) != ".xls" && Path.GetExtension(filename) != ".xlsx")
                {
                    MessageBox.Show("엑셀파일만 적용이 가능합니다! | " + Path.GetExtension(filename));
                    return;
                }

            }
            if (FilePath == "") return;

            FTP ftp = new FTP();

            // TODO: openFileDialog 사용. 파일경로 가져와야함.

            bool result = ftp.ConnectToServer();
            string path = @"";
            DirectoryInfo dirInfo = new DirectoryInfo(FilePath);
            FileInfo[] infos = dirInfo.GetFiles();

            if (result == true) 
            { 
                foreach(FileInfo info in dirInfo.GetFiles())
                {
                    if(Path.GetFileName(info.Name) == filename) {
                        if(ftp.UpLoad(path, info.FullName) == false) {
                            MessageBox.Show("FTP Upload 실패");
                        }
                        else {
                            MessageBox.Show("FTP Upload 성공");
                        }
                    }
                }
            }
            else { MessageBox.Show("접속 실패"); }

            // 바로빌 FAX API연동
            Barobill_FAX fax = new Barobill_FAX();
            fax.Send_BaroFax(filename, "", "");
            */
        }

    }
}