using OrderSheetSystem.model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OrderSheetSystem.lib;
using OrderSheetSystem.model;
using TheArtOfDev.HtmlRenderer.Core;
using TheArtOfDev.HtmlRenderer.Core.Entities;
using TheArtOfDev.HtmlRenderer.WinForms.Utilities;
using TheArtOfDev.HtmlRenderer.WinForms;
using lib;
using System.Drawing.Imaging;
using SixLabors.ImageSharp.Drawing;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
using System.Security.Cryptography.X509Certificates;
using static System.Runtime.CompilerServices.RuntimeHelpers;

namespace OrderSheetSystem
{
    public partial class FrmOrderSheet : Form
    {
        List<OrderSheet> OrderSheetList = new List<OrderSheet>();
        private System.Drawing.Printing.PrintDocument printDocument;
        private string printBuffer;
        TextProcessing textProcessing;
        IniFile ini;
        string selected_preset;
        Graphics graphics;
        Rectangle rect = new Rectangle(280, 35, 20, 20);
        SolidBrush redBrush = new SolidBrush(Color.Red);
        Dictionary<String, Preset> presets = new Dictionary<string, Preset>();
        private string printerName;

        public FrmOrderSheet()
        {
           
            InitializeComponent();
                      

            this.printDocument = new System.Drawing.Printing.PrintDocument();
            this.printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.ThePrintDocument_PrintLabel);

            graphics = base.CreateGraphics();
            graphics.FillEllipse(redBrush, rect);

            // Prepare settings from INI
            ini = new lib.IniFile("config.ini");
            selected_preset = "192.168.1.1"; // ini.Read("default", null);
            loadAllPreset(selected_preset);

            //Initialize text processing
            string input_format = ini.Read("input", selected_preset);
            char delimiter = '|'; // ini.Read("delimiter", null).ToCharArray()[0];
            textProcessing = new TextProcessing(input_format, delimiter);

            this.printerName = ini.Read("printer", selected_preset);

        }

        private void printLabel(object sender, EventArgs e, string strprintBuffer)
        {
            //ini.Write("printer", printerName, selected_preset);
            ini.Write("template", System.IO.Directory.GetCurrentDirectory() + "\\Template-Order.html", selected_preset);
            ini.Write("width", "800", selected_preset);
            ini.Write("height", "1600", selected_preset);

            this.printerName = ini.Read("printer", selected_preset);

            //Print Label
            if (setContentPrintBuffer(strprintBuffer))
            {
                printDocument.PrinterSettings.PrinterName = this.printerName;
                printDocument.Print();
            }
        }

        private bool setContentPrintBuffer(string str)
        {
            bool ret = true;
            Dictionary<string, VarObject> vars = textProcessing.ParseInput(str, '|');

            foreach (string key in vars.Keys)
            {
                VarObject v;
                vars.TryGetValue(key, out v);
            }

            //Read template content
            try
            {
                string html = System.IO.File.ReadAllText(ini.Read("template", selected_preset));

                //Process html
                html = TextProcessing.ReplaceVariables(textProcessing, html, ini);

                printBuffer = html;
            }
            catch (Exception e)
            {
                //log("Error: " + e.Message);
                ret = false;

            }

            return ret;
        }

        private void loadAllPreset(string defaultPreset = null)
        {
            bool isFound = false;

            // Flush old settings
            presets.Clear();
            //for (int i = menuPreset.DropDownItems.Count; i > 2; i--)
            //{
            //    menuPreset.DropDownItems.RemoveAt(i - 1);
            //}

            foreach (string preset_id in ini.Read("preset", null).Split(','))
            {
                try
                {
                    // Update menu
                    //ToolStripMenuItem menu = new ToolStripMenuItem(preset_id
                    //    , null, presetSelect_Click);
                    if (preset_id.Equals(defaultPreset))
                    {
                        //menu.Checked = true;
                        isFound = true;

                        //log("Info: preset found, use " + preset_id + " as default preset.");
                        selected_preset = preset_id;

                        // Update printer
                        //searchPrinters(ini.Read("printer", preset_id));
                    }
                    //menuPreset.DropDownItems.Add(menu);

                    // Keep loaded preset settings
                    presets.Add(preset_id,
                        new Preset(
                        preset_id,
                        ini.Read("printer", preset_id),
                        ini.Read("template", preset_id),
                        ini.Read("width", preset_id),
                        ini.Read("height", preset_id),
                        ini.Read("input", preset_id)
                        ));
                }
                catch (Exception e)
                {

                }
            }

            if (defaultPreset != null && !isFound)
            {
                //log("Error: default preset not found!, please choose the new one.");
            }
        }

        protected void ThePrintDocument_PrintLabel(object sender, System.Drawing.Printing.PrintPageEventArgs ev)
        {

            SolidBrush myBrush = new SolidBrush(Color.Black);

            Size size = new Size(800, 1600);

            //HTML render
            //Image image = TheArtOfDev.HtmlRenderer.WinForms.HtmlRender.RenderToImage(printBuffer);

            Image image = RenderToImage(printBuffer, size, Color.White, null);


            Rectangle rect = new Rectangle(0, 0, Int32.Parse("800"), Int32.Parse("1600"));
            ev.Graphics.DrawImage(image, rect);

            ev.HasMorePages = false;

            myBrush.Dispose();

        }

        public static Image RenderToImage(string html, Size size, Color backgroundColor = new Color(), CssData cssData = null,
            EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad = null, EventHandler<HtmlImageLoadEventArgs> imageLoad = null)
        {
            if (backgroundColor == Color.Transparent)
                throw new ArgumentOutOfRangeException("backgroundColor", "Transparent background in not supported");

            // create the final image to render into
            var image = new Bitmap(size.Width, size.Height, PixelFormat.Format32bppArgb);

            if (!string.IsNullOrEmpty(html))
            {
                // create memory buffer from desktop handle that supports alpha channel
                IntPtr dib;
                var memoryHdc = Win32Utils.CreateMemoryHdc(IntPtr.Zero, image.Width, image.Height, out dib);
                try
                {
                    // create memory buffer graphics to use for HTML rendering
                    using (var memoryGraphics = Graphics.FromHdc(memoryHdc))
                    {
                        memoryGraphics.Clear(backgroundColor != Color.Empty ? backgroundColor : Color.White);

                        // render HTML into the memory buffer
                        RenderHtml(memoryGraphics, html, PointF.Empty, size, cssData, true, stylesheetLoad, imageLoad);
                    }

                    // copy from memory buffer to image
                    CopyBufferToImage(memoryHdc, image);
                }
                finally
                {
                    Win32Utils.ReleaseMemoryHdc(memoryHdc, dib);
                }
            }

            return image;
        }

        private static void CopyBufferToImage(IntPtr memoryHdc, Image image)
        {
            using (var imageGraphics = Graphics.FromImage(image))
            {
                var imgHdc = imageGraphics.GetHdc();
                Win32Utils.BitBlt(imgHdc, 0, 0, image.Width, image.Height, memoryHdc, 0, 0, Win32Utils.BitBltCopy);
                imageGraphics.ReleaseHdc(imgHdc);
            }
        }

        private static SizeF RenderHtml(Graphics g, string html, PointF location, SizeF maxSize, CssData cssData, bool useGdiPlusTextRendering, EventHandler<HtmlStylesheetLoadEventArgs> stylesheetLoad, EventHandler<HtmlImageLoadEventArgs> imageLoad)
        {
            SizeF actualSize = SizeF.Empty;

            if (!string.IsNullOrEmpty(html))
            {
                using (var container = new HtmlContainer())
                {
                    container.Location = location;
                    container.MaxSize = maxSize;
                    container.AvoidAsyncImagesLoading = true;
                    container.AvoidImagesLateLoading = true;
                    container.UseGdiPlusTextRendering = useGdiPlusTextRendering;

                    if (stylesheetLoad != null)
                        container.StylesheetLoad += stylesheetLoad;
                    if (imageLoad != null)
                        container.ImageLoad += imageLoad;

                    container.SetHtml(html, cssData);
                    container.PerformLayout(g);
                    container.PerformPaint(g);

                    actualSize = container.ActualSize;
                }
            }

            return actualSize;
        }

        private void btnSettingCustomer_Click(object sender, EventArgs e)
        {
            FrmCustomer frmCustomer = new FrmCustomer();
            frmCustomer.ShowDialog();
            CustomerCombo();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FrmPartNoOrder frmPartNoOrder = new FrmPartNoOrder();
            frmPartNoOrder.ShowDialog();
            PartNoOrderCombo();
        }

        private void FrmOrderSheet_Load(object sender, EventArgs e)
        {
            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
            string version = fvi.FileVersion;

            this.Text = "Advics Order Sheet System V." + version;

            GatewayCombo();
            CustomerCombo();
            PartNoOrderCombo();

            //dgvSampleOrderList.Columns[1].Width = 600;
            dgvSampleOrderList.DataSource = OrderSheetList;
            dgvSampleOrderList.Columns[0].HeaderText = "Order Customer No.";
            dgvSampleOrderList.Columns[1].HeaderText = "Part No. Order";
            dgvSampleOrderList.Columns[2].HeaderText = "Qty";
            dgvSampleOrderList.Columns[3].HeaderText = "Customer";
            dgvSampleOrderList.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dgvSampleOrderList.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dgvSampleOrderList.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dgvSampleOrderList.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dgvSampleOrderList.Columns[2].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvSampleOrderList.ClearSelection();
        }

        private void CustomerCombo()
        {
            List<string> tmp = null;
            List<CustomerMaster> Customer = new List<CustomerMaster>();
            List<string> tmp11 = new List<string>();
            Int32 i = 0;
            tmp = null;
            using (var csv = new CsvReader(System.IO.Directory.GetCurrentDirectory() + "\\Customer.csv"))
            {
                while ((tmp = csv.ReadRow()) != null)
                {
                    //Customer.Add(tmp);

                    if (tmp[0] != "")
                    {
                        //    Customer.Add(new CustomerMaster() { Id = i + 1, Customer = tmp[0] });

                        //    i++;


                        for (int i1 = 0; i1 < tmp.Count(); i1++)
                        {
                            Customer.Add(new CustomerMaster() { No = i + 1, Customer = tmp[i] });
                            tmp11.Add(tmp[i1]);

                            i++;
                        }
                    }

                }

            }//using end

            var newList = tmp11.OrderBy(m => m).ToList();

            cmbCustomer.DataSource = newList;
            //cmbCustomer.Sorted = true;



        }

        private void GatewayCombo()
        {
            List<string> tmp = null;
            List<GatewayMaster> Gateway = new List<GatewayMaster>();
            List<string> tmp11 = new List<string>();
            Int32 i = 0;
            tmp = null;
            using (var csv = new CsvReader(System.IO.Directory.GetCurrentDirectory() + "\\Gateway.csv"))
            {
                while ((tmp = csv.ReadRow()) != null)
                {

                    if (tmp[0] != "")
                    {

                        tmp.Sort();

                        for (int i1 = 0; i1 < tmp.Count(); i1++)
                        {
                            string[] tmpGateway = tmp[i].Split('|');
                            Gateway.Add(new GatewayMaster() { No = i + 1, Gateway = tmpGateway[0], Code = tmpGateway[1] });
                            tmp11.Add(tmp[i1]);

                            i++;
                        }
                    }

                }

            }//using end

            //var newList = tmp11.OrderBy(m => m).ToList();

            //var newList = Gateway.OrderBy(m => m.Gateway).ToList();

            //cmbGateway.DataSource = newList;

            cmbGateway.DataSource = Gateway;

            //BindingList<GatewayMaster> _comboItems = new BindingList<GatewayMaster>();


            //cmbGateway.DataSource = _comboItems;

            cmbGateway.DisplayMember = "Gateway";

            cmbGateway.ValueMember = "Code";

            //MessageBox.Show(cmbGateway.SelectedValue.ToString());
        }

        private void PartNoOrderCombo()
        {
            List<string> tmp = null;
            List<PartNoOrderMaster> PartNoOrder = new List<PartNoOrderMaster>();
            List<string> tmp11 = new List<string>();
            Int32 i = 0;
            tmp = null;
            using (var csv = new CsvReader(System.IO.Directory.GetCurrentDirectory() + "\\PartNoOrder.csv"))
            {
                while ((tmp = csv.ReadRow()) != null)
                {

                    if (tmp[0] != "")
                    {

                        for (int i1 = 0; i1 < tmp.Count(); i1++)
                        {
                            PartNoOrder.Add(new PartNoOrderMaster() { No = i + 1, PartNoOrder = tmp[i] });

                            tmp11.Add(tmp[i1]);

                            i++;
                        }
                    }

                }

            }//using end

            var newList = tmp11.OrderBy(m => m).ToList();

            cmbPartNoOrder.DataSource = newList;
            //cmbPartNoOrder.Sorted = true;
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            //List<OrderSheet> OrderSheet = new List<OrderSheet>();

            if (txtOrderCustomerNo.Text.Trim() == "")
            {
                MessageBox.Show("ใส่ Order Customer No. ไม่ถูกต้อง", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                return;
            }

            if ((IsNumeric(txtQty.Text.Trim()) == false) || txtQty.Text.Trim() == "")
            {
                MessageBox.Show("ใส่จำนวนไม่ถูกต้อง", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                return;
            }

            if (dgvSampleOrderList.RowCount == 12)
            {
                MessageBox.Show("เพิ่มได้สูงสุด 12 แถว", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                return;
            }

            if (dgvSampleOrderList.RowCount == 0)
            {
                cmbGateway.Enabled = false;
                btnSettingGateway.Enabled = false;
                txtOrderCustomerNo.Enabled = false;
            }

            OrderSheetList.Add(new OrderSheet() { OrderCustomerNo = cmbGateway.SelectedValue.ToString().Trim() + txtOrderCustomerNo.Text.Trim(), PartNoOrder = cmbPartNoOrder.Text.Trim(), Qty = txtQty.Text.Trim(), Customer = cmbCustomer.Text.Trim() });

            BindingSource bindingSource1 = new BindingSource();
            bindingSource1.DataSource = OrderSheetList;

            //dgvSampleOrderList.DataSource = null;
            //dgvSampleOrderList.Update();
            //dgvSampleOrderList.Refresh();
            //dgvSampleOrderList.DataSource = OrderSheetList;
            dgvSampleOrderList.DataSource = bindingSource1;           
            dgvSampleOrderList.Columns[0].HeaderText = "Order Customer No.";
            dgvSampleOrderList.Columns[1].HeaderText = "Part No. Order";
            dgvSampleOrderList.Columns[2].HeaderText = "Qty";
            dgvSampleOrderList.Columns[3].HeaderText = "Customer";
            dgvSampleOrderList.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dgvSampleOrderList.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dgvSampleOrderList.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dgvSampleOrderList.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dgvSampleOrderList.Columns[2].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvSampleOrderList.Columns[2].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvSampleOrderList.ClearSelection();
        }

        public bool IsNumeric(string value)
        {
            return value.All(char.IsNumber);
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            //Print Label
            printLabelProcess(sender, e);
        }

        private void printLabelProcess(object sender, EventArgs e)
        {

            //if (printerStatus.BackColor == Color.LightGreen)
            //{

            string strQR = string.Empty;
            string[] arrayNo = new string[12];
            string[] arrayCustomerPartNo = new string[12];
            string[] arrayQty = new string[12];
            string[] arrayOrderCustomerNo = new string[12];
            string[] arrayCustomer = new string[12];

            for (int j = 0; j < 12; j++)
            {
                arrayNo[j] = string.Empty;
                arrayCustomerPartNo[j] = string.Empty;
                arrayQty[j] = string.Empty;
                arrayOrderCustomerNo[j] = string.Empty;
                arrayCustomer[j] = string.Empty;
            }

            for (int i = 0; i < dgvSampleOrderList.RowCount; i++)
            {
                arrayNo[i] = (i + 1).ToString();
                arrayCustomerPartNo[i] = dgvSampleOrderList[1, i].Value.ToString();
                arrayQty[i] = dgvSampleOrderList[2, i].Value.ToString();
                arrayOrderCustomerNo[i] = dgvSampleOrderList[0, i].Value.ToString();
                arrayCustomer[i] = dgvSampleOrderList[3, i].Value.ToString();

                if ((i == 0) && (i != dgvSampleOrderList.RowCount - 1))
                {
                    strQR = dgvSampleOrderList[0, i].Value.ToString() + ","
                    + dgvSampleOrderList[1, i].Value.ToString() + ","
                    + dgvSampleOrderList[2, i].Value.ToString() + "\r\n";
                }
                else if ((i == 0) && (i == dgvSampleOrderList.RowCount - 1))
                {
                    strQR = dgvSampleOrderList[0, i].Value.ToString() + ","
                    + dgvSampleOrderList[1, i].Value.ToString() + ","
                    + dgvSampleOrderList[2, i].Value.ToString() + "\r\n"
                    + "$";
                }
                else if (i == dgvSampleOrderList.RowCount - 1)
                {
                    strQR = strQR + dgvSampleOrderList[0, i].Value.ToString() + ","
                    + dgvSampleOrderList[1, i].Value.ToString() + ","
                    + dgvSampleOrderList[2, i].Value.ToString() + "\r\n"
                    + "$";
                }
                else
                {
                    strQR = strQR + dgvSampleOrderList[0, i].Value.ToString() + ","
                    + dgvSampleOrderList[1, i].Value.ToString() + ","
                    + dgvSampleOrderList[2, i].Value.ToString() + "\r\n";
                }
            }

            printLabel(sender, e, DateTime.Now.ToString("M/dd/yyyy") + "|" +
            cmbGateway.SelectedValue.ToString().Trim() + txtOrderCustomerNo.Text.Trim() + "|" +
            strQR + "|" +
            arrayNo[0] + "|" + arrayCustomerPartNo[0] + "|" + arrayQty[0] + "|" + arrayOrderCustomerNo[0] + "|" + arrayCustomer[0] + "|" +
            arrayNo[1] + "|" + arrayCustomerPartNo[1] + "|" + arrayQty[1] + "|" + arrayOrderCustomerNo[1] + "|" + arrayCustomer[1] + "|" +
            arrayNo[2] + "|" + arrayCustomerPartNo[2] + "|" + arrayQty[2] + "|" + arrayOrderCustomerNo[2] + "|" + arrayCustomer[2] + "|" +
            arrayNo[3] + "|" + arrayCustomerPartNo[3] + "|" + arrayQty[3] + "|" + arrayOrderCustomerNo[3] + "|" + arrayCustomer[3] + "|" +
            arrayNo[4] + "|" + arrayCustomerPartNo[4] + "|" + arrayQty[4] + "|" + arrayOrderCustomerNo[4] + "|" + arrayCustomer[4] + "|" +
            arrayNo[5] + "|" + arrayCustomerPartNo[5] + "|" + arrayQty[5] + "|" + arrayOrderCustomerNo[5] + "|" + arrayCustomer[5] + "|" +
            arrayNo[6] + "|" + arrayCustomerPartNo[6] + "|" + arrayQty[6] + "|" + arrayOrderCustomerNo[6] + "|" + arrayCustomer[6] + "|" +
            arrayNo[7] + "|" + arrayCustomerPartNo[7] + "|" + arrayQty[7] + "|" + arrayOrderCustomerNo[7] + "|" + arrayCustomer[7] + "|" +
            arrayNo[8] + "|" + arrayCustomerPartNo[8] + "|" + arrayQty[8] + "|" + arrayOrderCustomerNo[8] + "|" + arrayCustomer[8] + "|" +
            arrayNo[9] + "|" + arrayCustomerPartNo[9] + "|" + arrayQty[9] + "|" + arrayOrderCustomerNo[9] + "|" + arrayCustomer[9] + "|" +
            arrayNo[10] + "|" + arrayCustomerPartNo[10] + "|" + arrayQty[10] + "|" + arrayOrderCustomerNo[10] + "|" + arrayCustomer[10] + "|" +
            arrayNo[11] + "|" + arrayCustomerPartNo[11] + "|" + arrayQty[11] + "|" + arrayOrderCustomerNo[11] + "|" + arrayCustomer[11] + "|" +
            DateTime.Now.ToString("dd-MM-yyyy") + "|" +
            DateTime.Now.ToString("HH:mm"));



            //}
            //else
            //{
            //    MessageBox.Show(this, "ไม่สามารถเพิมพ์ได้ เนื่องจาก Printer Offline",
            //                       "Print Label", MessageBoxButtons.OK,
            //                       MessageBoxIcon.Error,
            //                       MessageBoxDefaultButton.Button1, 0);

            //    printPriviewLabel(sender, e, "" + "|" + QRStyle + "|" + strQR + "|" +
            //                        CustomerStyle + "|" + strCustomerName + "|" +
            //                        LocationStyle + "|" + strLocation + "|" +
            //                        SIDEStyle + "|" + strSIDE + "|" +
            //                        QTYStyle + "|" + lblQPack.Text + "| " +
            //                        PartNameStyle + "|" + lblPartName.Text + "|" +
            //                        UserNameStyle + "|" + userName + "|" +
            //                        SerialStyle + "|" + strMaxSerial + "|" +
            //                        ADSPartNoStyle + "|" + lblPartNo.Text + "|" +
            //                        CustomerPartNoStyle + "|" + strCustomerPartNO + "|" +
            //                        ScanDateStyle + "|" + ScanTimeStyle + "|" + DateTime.Now.ToString("yyyyMMddHHmmss") + "|" +
            //                        ModelStyle + "|" + lblModelShow.Text + "|" + DetailStyle + "|" + strDetail);

            //}
        }

        private void btnNew_Click(object sender, EventArgs e)
        {
            cmbGateway.Enabled = true;
            btnSettingGateway.Enabled = true;
            txtOrderCustomerNo.Enabled = true;

            OrderSheetList = new List<OrderSheet>();
            dgvSampleOrderList.DataSource = null;
            dgvSampleOrderList.Update();
            dgvSampleOrderList.Refresh();
            dgvSampleOrderList.DataSource = OrderSheetList;
            dgvSampleOrderList.Columns[0].HeaderText = "Order Customer No.";
            dgvSampleOrderList.Columns[1].HeaderText = "Part No. Order";
            dgvSampleOrderList.Columns[2].HeaderText = "Qty";
            dgvSampleOrderList.Columns[3].HeaderText = "Customer";
            dgvSampleOrderList.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dgvSampleOrderList.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dgvSampleOrderList.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dgvSampleOrderList.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dgvSampleOrderList.Columns[2].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvSampleOrderList.Columns[2].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvSampleOrderList.ClearSelection();
        }

        private void btnSettingGateway_Click(object sender, EventArgs e)
        {
            FrmGateway frmGateway = new FrmGateway();
            frmGateway.ShowDialog();
            GatewayCombo();
        }

        private void dgvSampleOrderList_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void dgvSampleOrderList_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            
        }

        private void dgvSampleOrderList_Click(object sender, EventArgs e)
        {
            
        }
    }
}
