using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.Reflection;
using System.Windows.Forms;
using CsvHelper.Configuration.Attributes;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
//using Microsoft.Office.Interop.Excel;

namespace PackingControlSystem.lib
{
    internal class clsUtil_MSSQL
    {
        //public static string dbConStr = "Data Source=localhost/MSSQL2019;Initial Catalog=TCSDB;User Id=sa;Password=Fm,ylgm82021;";
        // no need *** NetWork Library=dbmssocn; *** 

        private bool dbConnect()
        {
            bool ans = false;


            return ans;
        }

        private bool dbDisConnect()
        {
            bool ans = false;


            return ans;
        }

        public static void updatePart(string dbconLocal, int ROWID, string PartID, string Model, string ModelCode, string PartName,
            string CustomerPartName, string PartNO, string CustomerPartNO, int QTY, int CircleTime, int DryLifeTime,
            int WetLifeTime, int QRLength, string CUSTOMERID, string editUserName, string editSystemDate, string editSystemTime,
            string Location, int ModelStart, int ModelLength, int DateStart,
            int DateLength, string Packaging, byte[] PhotoSpec1, byte[] PhotoSpec2, string SIDE, string Type, string Wet, string Detail)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {


                                command.CommandText = @"UPDATE TM_PARTS set PARTID=@PartID, MODEL=@Model, MODEL_CODE=@ModelCode, PART_NAME=@PartName,
                                                        CUST_PART_NAME=@CustomerPartName, CUST_PART_NUM=@CustomerPartNo,QPACK=@QTY, CTIME=@CircleTime, DRYTIME=@DryLifeTime,
                                                        WETTIME=@WetLifeTime, QRLEN=@QRLength, CUSTOMERID=@CUSTOMERID, EDITBY=@editUserName, EDITDATE=@editSystemDate, 
                                                        EDITTIME=@editSystemTime, REMARK1=@Location, REMARK2=@Packaging,
                                                        REMARK3=@ModelStart, REMARK4=@ModelLength, REMARK5=@Detail, NUMBER1=@DateStart, NUMBER2=@DateLength, SIDE=@SIDE,  TYPE=@Type, WET_TYPE=@Wet
                                                        WHERE ROWID=@ROWID and PART_NUM=@PartNO;";

                                command.Parameters.Add(new SqlParameter("@ROWID", ROWID));
                                command.Parameters.Add(new SqlParameter("@PartNO", PartNO));
                                command.Parameters.Add(new SqlParameter("@PartID", PartID));
                                command.Parameters.Add(new SqlParameter("@Model", Model));
                                command.Parameters.Add(new SqlParameter("@ModelCode", ModelCode));
                                command.Parameters.Add(new SqlParameter("@PartName", PartName));
                                command.Parameters.Add(new SqlParameter("@CustomerPartName", CustomerPartName));
                                command.Parameters.Add(new SqlParameter("@CustomerPartNo", CustomerPartNO));
                                command.Parameters.Add(new SqlParameter("@QTY", QTY));
                                command.Parameters.Add(new SqlParameter("@CircleTime", CircleTime));
                                command.Parameters.Add(new SqlParameter("@DryLifeTime", DryLifeTime));
                                command.Parameters.Add(new SqlParameter("@WetLifeTime", WetLifeTime));
                                command.Parameters.Add(new SqlParameter("@QRLength", QRLength));
                                command.Parameters.Add(new SqlParameter("@CUSTOMERID", CUSTOMERID));
                                command.Parameters.Add(new SqlParameter("@editUserName", editUserName));
                                command.Parameters.Add(new SqlParameter("@editSystemDate", editSystemDate));
                                command.Parameters.Add(new SqlParameter("@editSystemTime", editSystemTime));
                                command.Parameters.Add(new SqlParameter("@Location", Location));
                                command.Parameters.Add(new SqlParameter("@Packaging", Packaging));
                                command.Parameters.Add(new SqlParameter("@ModelStart", ModelStart));
                                command.Parameters.Add(new SqlParameter("@ModelLength", ModelLength));
                                command.Parameters.Add(new SqlParameter("@DateStart", DateStart));
                                command.Parameters.Add(new SqlParameter("@DateLength", DateLength));
                                command.Parameters.Add(new SqlParameter("@SIDE", SIDE));
                                command.Parameters.Add(new SqlParameter("@Type", Type));
                                command.Parameters.Add(new SqlParameter("@Wet", Wet));
                                command.Parameters.Add(new SqlParameter("@Detail", Detail));

                                command.ExecuteNonQuery();

                            }


                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {
                                if (PhotoSpec1 != null && PhotoSpec2 != null)
                                {
                                    command.CommandText = @"UPDATE TM_PARTS_FILES set FILE1=@PhotoSpec1, FILE2=@PhotoSpec2 WHERE MPROWID=@ROWID and PART_NUM=@PartNO;";

                                    command.Parameters.Add(new SqlParameter("@ROWID", ROWID));
                                    command.Parameters.Add(new SqlParameter("@PartNO", PartNO));
                                    command.Parameters.Add(new SqlParameter("@PhotoSpec1", PhotoSpec1));
                                    command.Parameters.Add(new SqlParameter("@PhotoSpec2", PhotoSpec2));

                                    command.ExecuteNonQuery();
                                }
                                else if (PhotoSpec1 != null && PhotoSpec2 == null)
                                {
                                    command.CommandText = @"UPDATE TM_PARTS_FILES set FILE1=@PhotoSpec1 WHERE MPROWID=@ROWID and PART_NUM=@PartNO;";

                                    command.Parameters.Add(new SqlParameter("@ROWID", ROWID));
                                    command.Parameters.Add(new SqlParameter("@PartNO", PartNO));
                                    command.Parameters.Add(new SqlParameter("@PhotoSpec1", PhotoSpec1));


                                    command.ExecuteNonQuery();
                                }
                                else if (PhotoSpec1 == null && PhotoSpec2 != null)
                                {
                                    command.CommandText = @"UPDATE TM_PARTS_FILES set FILE2=@PhotoSpec2 WHERE MPROWID=@ROWID and PART_NUM=@PartNO;";

                                    command.Parameters.Add(new SqlParameter("@ROWID", ROWID));
                                    command.Parameters.Add(new SqlParameter("@PartNO", PartNO));
                                    command.Parameters.Add(new SqlParameter("@PhotoSpec2", PhotoSpec2));


                                    command.ExecuteNonQuery();
                                }



                            }
                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static void updateSetting(string dbconLocal, Int32 ModelNameX
      , Int32 ModelNameY
      , Int32 ModelNameFS
      , Int32 CustomerNameX
      , Int32 CustomerNameY
      , Int32 CustomerNameFS
      , Int32 CustomerCodeX
      , Int32 CustomerCodeY
      , Int32 CustomerCodeFS
      , Int32 QtyX
      , Int32 QtyY
      , Int32 QtyFS
      , Int32 UserNameX
      , Int32 UserNameY
      , Int32 UserNameFS
      , Int32 SerialNoX
      , Int32 SerialNoY
      , Int32 SerialNoFS
      , Int32 PartNoX
      , Int32 PartNoY
      , Int32 PartNoFS
      , Int32 CustomerPartNoX
      , Int32 CustomerPartNoY
      , Int32 CustomerPartNoFS
      , Int32 LocationX
      , Int32 LocationY
      , Int32 LocationFS
      , Int32 SIDEX
      , Int32 SIDEY
      , Int32 SIDEFS
      , Int32 DateX
      , Int32 DateY
      , Int32 DateFS
      , Int32 TimeX
      , Int32 TimeY
      , Int32 TimeFS
      , Int32 QRX
      , Int32 QRY
      , Int32 QRFS
      , Int32 DetailX
      , Int32 DetailY
      , Int32 DetailFS
      , string Username, string editSystemDate, string editSystemTime)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {


                                command.CommandText = @"UPDATE TM_SETTING set ModelNameX=@ModelNameX, ModelNameY=@ModelNameY, ModelNameFS=@ModelNameFS 
                                                        , CustomerNameX=@CustomerNameX, CustomerNameY=@CustomerNameY, CustomerNameFS=@CustomerNameFS
                                                        , CustomerCodeX=@CustomerCodeX, CustomerCodeY=@CustomerCodeY, CustomerCodeFS=@CustomerCodeFS
                                                        , QtyX=@QtyX, QtyY=@QtyY, QtyFS=@QtyFS
                                                        , UserNameX=@UserNameX, UserNameY=@UserNameY, UserNameFS=@UserNameFS
                                                        , SerialNoX=@SerialNoX, SerialNoY=@SerialNoY, SerialNoFS=@SerialNoFS
                                                        , PartNoX=@PartNoX, PartNoY=@PartNoY, PartNoFS=@PartNoFS
                                                        , CustomerPartNoX=@CustomerPartNoX, CustomerPartNoY=@CustomerPartNoY, CustomerPartNoFS=@CustomerPartNoFS
                                                        , LocationX=@LocationX, LocationY=@LocationY, LocationFS=@LocationFS
                                                        , SIDEX=@SIDEX, SIDEY=@SIDEY, SIDEFS=@SIDEFS
                                                        , DateX=@DateX, DateY=@DateY, DateFS=@DateFS
                                                        , TimeX=@TimeX, TimeY=@TimeY, TimeFS=@TimeFS
                                                        , QRX=@QRX, QRY=@QRY, QRFS=@QRFS
                                                        , DetailX=@DetailX, DetailY=@DetailY, DetailFS=@DetailFS
                                                        , EDITBY=@Username 
                                                        , EDITDATE=@editSystemDate, EDITTIME=@editSystemTime 
                                                         ;";

                                command.Parameters.Add(new SqlParameter("@ModelNameX", ModelNameX));
                                command.Parameters.Add(new SqlParameter("@ModelNameY", ModelNameY));
                                command.Parameters.Add(new SqlParameter("@ModelNameFS", ModelNameFS));
                                command.Parameters.Add(new SqlParameter("@CustomerNameX", CustomerNameX));
                                command.Parameters.Add(new SqlParameter("@CustomerNameY", CustomerNameY));
                                command.Parameters.Add(new SqlParameter("@CustomerNameFS", CustomerNameFS));
                                command.Parameters.Add(new SqlParameter("@CustomerCodeX", CustomerCodeX));
                                command.Parameters.Add(new SqlParameter("@CustomerCodeY", CustomerCodeY));
                                command.Parameters.Add(new SqlParameter("@CustomerCodeFS", CustomerCodeFS));
                                command.Parameters.Add(new SqlParameter("@QtyX", QtyX));
                                command.Parameters.Add(new SqlParameter("@QtyY", QtyY));
                                command.Parameters.Add(new SqlParameter("@QtyFS", QtyFS));
                                command.Parameters.Add(new SqlParameter("@UserNameX", UserNameX));
                                command.Parameters.Add(new SqlParameter("@UserNameY", UserNameY));
                                command.Parameters.Add(new SqlParameter("@UserNameFS", UserNameFS));
                                command.Parameters.Add(new SqlParameter("@SerialNoX", SerialNoX));
                                command.Parameters.Add(new SqlParameter("@SerialNoY", SerialNoY));
                                command.Parameters.Add(new SqlParameter("@SerialNoFS", SerialNoFS));
                                command.Parameters.Add(new SqlParameter("@PartNoX", PartNoX));
                                command.Parameters.Add(new SqlParameter("@PartNoY", PartNoY));
                                command.Parameters.Add(new SqlParameter("@PartNoFS", PartNoFS));
                                command.Parameters.Add(new SqlParameter("@CustomerPartNoX", CustomerPartNoX));
                                command.Parameters.Add(new SqlParameter("@CustomerPartNoY", CustomerPartNoY));
                                command.Parameters.Add(new SqlParameter("@CustomerPartNoFS", CustomerPartNoFS));
                                command.Parameters.Add(new SqlParameter("@LocationX", LocationX));
                                command.Parameters.Add(new SqlParameter("@LocationY", LocationY));
                                command.Parameters.Add(new SqlParameter("@LocationFS", LocationFS));
                                command.Parameters.Add(new SqlParameter("@SIDEX", SIDEX));
                                command.Parameters.Add(new SqlParameter("@SIDEY", SIDEY));
                                command.Parameters.Add(new SqlParameter("@SIDEFS", SIDEFS));
                                command.Parameters.Add(new SqlParameter("@DateX", DateX));
                                command.Parameters.Add(new SqlParameter("@DateY", DateY));
                                command.Parameters.Add(new SqlParameter("@DateFS", DateFS));
                                command.Parameters.Add(new SqlParameter("@TimeX", TimeX));
                                command.Parameters.Add(new SqlParameter("@TimeY", TimeY));
                                command.Parameters.Add(new SqlParameter("@TimeFS", TimeFS));
                                command.Parameters.Add(new SqlParameter("@QRX", QRX));
                                command.Parameters.Add(new SqlParameter("@QRY", QRY));
                                command.Parameters.Add(new SqlParameter("@QRFS", QRFS));
                                command.Parameters.Add(new SqlParameter("@DetailX", DetailX));
                                command.Parameters.Add(new SqlParameter("@DetailY", DetailY));
                                command.Parameters.Add(new SqlParameter("@DetailFS", DetailFS));

                                command.Parameters.Add(new SqlParameter("@Username", Username));
                                command.Parameters.Add(new SqlParameter("@editSystemDate", editSystemDate));
                                command.Parameters.Add(new SqlParameter("@editSystemTime", editSystemTime));

                                command.ExecuteNonQuery();

                            }

                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static void updateSettingPLC(string dbconLocal, string IP
      , string Port
      , bool TUse
      , bool CSPUse
      , bool CDUse
      , string Username, string editSystemDate, string editSystemTime, string ProcessNo, bool ReInputUse)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {


                                command.CommandText = @"UPDATE TM_SETTING_PLC set IP=@IP, Port=@Port, TUse=@TUse 
                                                        , CSPUse=@CSPUse , CDUse=@CDUse

                                                        , EDITBY=@Username 
                                                        , EDITDATE=@editSystemDate, EDITTIME=@editSystemTime, ProcessNo=@ProcessNo 
                                                        , ReInputUse=@ReInputUse
                                                         ;";

                                command.Parameters.Add(new SqlParameter("@IP", IP));
                                command.Parameters.Add(new SqlParameter("@Port", Port));
                                command.Parameters.Add(new SqlParameter("@TUse", TUse));
                                command.Parameters.Add(new SqlParameter("@CSPUse", CSPUse));
                                command.Parameters.Add(new SqlParameter("@CDUse", CDUse));

                                command.Parameters.Add(new SqlParameter("@Username", Username));
                                command.Parameters.Add(new SqlParameter("@editSystemDate", editSystemDate));
                                command.Parameters.Add(new SqlParameter("@editSystemTime", editSystemTime));
                                command.Parameters.Add(new SqlParameter("@ProcessNo", ProcessNo));
                                command.Parameters.Add(new SqlParameter("@ReInputUse", ReInputUse));

                                command.ExecuteNonQuery();

                            }

                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }


        public static void updateUser(string dbconLocal, string userID, string Username, string Password,
            string Permission, bool Status, string editSystemDate, string editSystemTime)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {


                                command.CommandText = @"UPDATE TM_USER set NAME=@Username, PASSWORD=@Password, PERMISSION=@Permission, ENABLE=@Status 
                                                        , EDITDATE=@editSystemDate, EDITTIME=@editSystemTime 
                                                        WHERE USERID=@userID ;";

                                command.Parameters.Add(new SqlParameter("@userID", userID));
                                command.Parameters.Add(new SqlParameter("@Username", Username));
                                command.Parameters.Add(new SqlParameter("@Password", Password));
                                command.Parameters.Add(new SqlParameter("@Permission", Permission));
                                command.Parameters.Add(new SqlParameter("@Status", Status));
                                command.Parameters.Add(new SqlParameter("@editSystemDate", editSystemDate));
                                command.Parameters.Add(new SqlParameter("@editSystemTime", editSystemTime));

                                command.ExecuteNonQuery();

                            }

                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static void updateCustomer(string dbconLocal, string customerID, string CustomerName,
            string userName, string editSystemDate, string editSystemTime)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {


                                command.CommandText = @"UPDATE TM_CUSTOMER set CUSTOMER=@CustomerName, EDITBY=@userName 
                                                        , EDITDATE=@editSystemDate, EDITTIME=@editSystemTime 
                                                        WHERE CUSTOMERID=@customerID ;";

                                command.Parameters.Add(new SqlParameter("@customerID", customerID));
                                command.Parameters.Add(new SqlParameter("@CustomerName", CustomerName));
                                command.Parameters.Add(new SqlParameter("@userName", userName));
                                command.Parameters.Add(new SqlParameter("@editSystemDate", editSystemDate));
                                command.Parameters.Add(new SqlParameter("@editSystemTime", editSystemTime));

                                command.ExecuteNonQuery();

                            }

                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static void updateFinishKanban(string dbconLocal, string status, string SERIAL,
            string userName, string editSystemDate, string editSystemTime, string kanban)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {

                                if (status == "Printed")
                                {
                                    command.CommandText = @"UPDATE  TT_KANBAN_H set REMARK3=@status, EDITBY=@userName 
                                                        , EDITDATE=@editSystemDate, EDITTIME=@editSystemTime 
                                                        WHERE SERIAL=@SERIAL and REMARK3 <> 'Cancel';";

                                    command.Parameters.Add(new SqlParameter("@status", status));
                                    command.Parameters.Add(new SqlParameter("@SERIAL", SERIAL));
                                    command.Parameters.Add(new SqlParameter("@userName", userName));
                                    command.Parameters.Add(new SqlParameter("@editSystemDate", editSystemDate));
                                    command.Parameters.Add(new SqlParameter("@editSystemTime", editSystemTime));

                                }
                                else if (status == "Finish")
                                {
                                    command.CommandText = @"UPDATE  TT_KANBAN_H set REMARK3=@status, EDITBY=@userName 
                                                        , EDITDATE=@editSystemDate, EDITTIME=@editSystemTime 
                                                        WHERE FRMQRKANBAN=@kanban and REMARK3 <> 'Cancel';";

                                    command.Parameters.Add(new SqlParameter("@status", status));
                                    command.Parameters.Add(new SqlParameter("@kanban", kanban));
                                    command.Parameters.Add(new SqlParameter("@userName", userName));
                                    command.Parameters.Add(new SqlParameter("@editSystemDate", editSystemDate));
                                    command.Parameters.Add(new SqlParameter("@editSystemTime", editSystemTime));
                                }

                                

                                command.ExecuteNonQuery();

                            }

                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static void updateCancelKanban(string dbconLocal, string status, Int32 rowID,
            string userName, string editSystemDate, string editSystemTime)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {


                                command.CommandText = @"UPDATE  TT_KANBAN_H set REMARK3=@status, EDITBY=@userName 
                                                        , EDITDATE=@editSystemDate, EDITTIME=@editSystemTime 
                                                        WHERE KBHROWID=@rowID ;";

                                command.Parameters.Add(new SqlParameter("@status", status));
                                command.Parameters.Add(new SqlParameter("@rowID", rowID));
                                command.Parameters.Add(new SqlParameter("@userName", userName));
                                command.Parameters.Add(new SqlParameter("@editSystemDate", editSystemDate));
                                command.Parameters.Add(new SqlParameter("@editSystemTime", editSystemTime));

                                command.ExecuteNonQuery();

                            }

                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static void updateCancelKanbanPacking(string dbconLocal, string status, string strMaxSerial,
            string userName, string editSystemDate, string editSystemTime)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {


                                command.CommandText = @"UPDATE  TT_KANBAN_H set REMARK3=@status, EDITBY=@userName 
                                                        , EDITDATE=@editSystemDate, EDITTIME=@editSystemTime 
                                                        WHERE SERIAL=@strMaxSerial ;";

                                command.Parameters.Add(new SqlParameter("@status", status));
                                command.Parameters.Add(new SqlParameter("@strMaxSerial", strMaxSerial));
                                command.Parameters.Add(new SqlParameter("@userName", userName));
                                command.Parameters.Add(new SqlParameter("@editSystemDate", editSystemDate));
                                command.Parameters.Add(new SqlParameter("@editSystemTime", editSystemTime));

                                command.ExecuteNonQuery();

                            }

                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static void updatePackingHoldKanban(string dbconLocal, string status,
            string userName, string editSystemDate, string editSystemTime, string statusFirst, string kanban)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {


                                command.CommandText = @"UPDATE  TT_KANBAN_H set REMARK3=@status, EDITBY=@userName 
                                                        , EDITDATE=@editSystemDate, EDITTIME=@editSystemTime 
                                                        WHERE REMARK3=@statusFirst and FRMQRKANBAN = '" + kanban + "' ;";

                                command.Parameters.Add(new SqlParameter("@status", status));
                                command.Parameters.Add(new SqlParameter("@userName", userName));
                                command.Parameters.Add(new SqlParameter("@editSystemDate", editSystemDate));
                                command.Parameters.Add(new SqlParameter("@editSystemTime", editSystemTime));
                                command.Parameters.Add(new SqlParameter("@statusFirst", statusFirst));

                                command.ExecuteNonQuery();

                            }

                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static void updateCancelQRScan(string dbconLocal, string status, Int32 rowID,
            string userName, string editSystemDate, string editSystemTime)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {


                                command.CommandText = @"UPDATE  TT_KANBAN_L set REMARK3=@status, EDITBY=@userName 
                                                        , EDITDATE=@editSystemDate, EDITTIME=@editSystemTime 
                                                        WHERE KBHROWID=@rowID and REMARK3 <> 'NG';";

                                command.Parameters.Add(new SqlParameter("@status", status));
                                command.Parameters.Add(new SqlParameter("@rowID", rowID));
                                command.Parameters.Add(new SqlParameter("@userName", userName));
                                command.Parameters.Add(new SqlParameter("@editSystemDate", editSystemDate));
                                command.Parameters.Add(new SqlParameter("@editSystemTime", editSystemTime));

                                command.ExecuteNonQuery();

                            }

                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static void updateCancelQRScanSerial(string dbconLocal, string status, string QRScanSerial,
            string userName, string editSystemDate, string editSystemTime)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {


                                command.CommandText = @"UPDATE  TT_KANBAN_L set REMARK3=@status, EDITBY=@userName 
                                                        , EDITDATE=@editSystemDate, EDITTIME=@editSystemTime 
                                                        WHERE QRSERIAL=@QRScanSerial and REMARK3 <> 'NG';";

                                command.Parameters.Add(new SqlParameter("@status", status));
                                command.Parameters.Add(new SqlParameter("@QRScanSerial", QRScanSerial));
                                command.Parameters.Add(new SqlParameter("@userName", userName));
                                command.Parameters.Add(new SqlParameter("@editSystemDate", editSystemDate));
                                command.Parameters.Add(new SqlParameter("@editSystemTime", editSystemTime));

                                command.ExecuteNonQuery();

                            }

                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static void updateHoldQRScan(string dbconLocal, string status, string serialSelect,
            string userName, string editSystemDate, string editSystemTime)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {


                                command.CommandText = @"UPDATE  TT_KANBAN_L set REMARK3=@status, EDITBY=@userName 
                                                        , EDITDATE=@editSystemDate, EDITTIME=@editSystemTime 
                                                        WHERE QRSERIAL=@serialSelect ;";

                                command.Parameters.Add(new SqlParameter("@status", status));
                                command.Parameters.Add(new SqlParameter("@serialSelect", serialSelect));
                                command.Parameters.Add(new SqlParameter("@userName", userName));
                                command.Parameters.Add(new SqlParameter("@editSystemDate", editSystemDate));
                                command.Parameters.Add(new SqlParameter("@editSystemTime", editSystemTime));

                                command.ExecuteNonQuery();

                            }

                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static void updatePackingHoldQRScan(string dbconLocal, string status,
            string userName, string editSystemDate, string editSystemTime, string statusFirst, Int32 id)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {


                                command.CommandText = @"UPDATE  TT_KANBAN_L set REMARK3=@status, EDITBY=@userName 
                                                        , EDITDATE=@editSystemDate, EDITTIME=@editSystemTime 
                                                        WHERE REMARK3=@statusFirst and KBHROWID = " + id + " ;";

                                command.Parameters.Add(new SqlParameter("@status", status));
                                command.Parameters.Add(new SqlParameter("@userName", userName));
                                command.Parameters.Add(new SqlParameter("@editSystemDate", editSystemDate));
                                command.Parameters.Add(new SqlParameter("@editSystemTime", editSystemTime));
                                command.Parameters.Add(new SqlParameter("@statusFirst", statusFirst));

                                command.ExecuteNonQuery();

                            }

                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static void deletePart(string dbconLocal, int ROWID, string PartNO)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {


                                command.CommandText = @"delete from TM_PARTS WHERE ROWID=@ROWID and PART_NUM=@PartNO;";

                                command.Parameters.Add(new SqlParameter("@ROWID", ROWID));
                                command.Parameters.Add(new SqlParameter("@PartNO", PartNO));

                                command.ExecuteNonQuery();

                            }


                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {
                                command.CommandText = @"delete from TM_PARTS_FILES WHERE MPROWID=@ROWID and PART_NUM=@PartNO;";

                                command.Parameters.Add(new SqlParameter("@ROWID", ROWID));
                                command.Parameters.Add(new SqlParameter("@PartNO", PartNO));

                                command.ExecuteNonQuery();



                            }
                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static void deleteUser(string dbconLocal, string userID)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {


                                command.CommandText = @"delete from TM_USER WHERE USERID=@userID ;";

                                command.Parameters.Add(new SqlParameter("@userID", userID));

                                command.ExecuteNonQuery();

                            }



                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static void deleteCustomer(string dbconLocal, string customerID)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {


                                command.CommandText = @"delete from TM_CUSTOMER WHERE CUSTOMERID=@customerID ;";

                                command.Parameters.Add(new SqlParameter("@customerID", customerID));

                                command.ExecuteNonQuery();

                            }



                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static void insertPart(string dbconLocal, string PartID, string Model, string ModelCode, string PartName,
            string CustomerPartName, string PartNO, string CustomerPartNO, string addUserName, string addSystemDate,
            string addSystemTime, string editUserName, string editSystemDate, string editSystemTime,
            int QTY, int CircleTime, int DryLifeTime,
            int WetLifeTime, int QRLength, string CUSTOMERID, string Location,
            int ModelStart, int ModelLength, int DateStart,
            int DateLength, string Packaging, string SIDE, string Type, string Wet, string Detail)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {

                                command.CommandText = @"INSERT INTO TM_PARTS (PARTID, MODEL, MODEL_CODE, PART_NAME, CUST_PART_NAME, PART_NUM, CUST_PART_NUM, QPACK,
                                                        CTIME, DRYTIME, WETTIME, QRLEN, CUSTOMERID, ENABLE, CREATEBY, CREATEDATE, CREATETIME, EDITBY, EDITDATE, EDITTIME
                                                        , REMARK1,REMARK2,REMARK3, REMARK4, NUMBER1, NUMBER2, SIDE, TYPE, WET_TYPE, REMARK5) 
                                                        VALUES (@PartID,@Model,@ModelCode,@PartName,@CustomerPartName,@PartNO,@CustomerPartNO,@QTY,@CircleTime
                                                        ,@DryLifeTime,@WetLifeTime,@QRLength,@CUSTOMERID, @ENABLE, @addUserName, @addSystemDate, @addSystemTime
                                                        ,@editUserName,@editSystemDate,@editSystemTime
                                                        ,@Location,@Packaging,@ModelStart,@ModelLength,@DateStart,@DateLength, @SIDE, @Type, @Wet, @Detail)";


                                command.Parameters.Add(new SqlParameter("@PartNO", PartNO));
                                command.Parameters.Add(new SqlParameter("@PartID", PartID));
                                command.Parameters.Add(new SqlParameter("@Model", Model));
                                command.Parameters.Add(new SqlParameter("@ModelCode", ModelCode));
                                command.Parameters.Add(new SqlParameter("@PartName", PartName));
                                command.Parameters.Add(new SqlParameter("@CustomerPartName", CustomerPartName));
                                command.Parameters.Add(new SqlParameter("@CustomerPartNO", CustomerPartNO));
                                command.Parameters.Add(new SqlParameter("@QTY", QTY));
                                command.Parameters.Add(new SqlParameter("@CircleTime", CircleTime));
                                command.Parameters.Add(new SqlParameter("@DryLifeTime", DryLifeTime));
                                command.Parameters.Add(new SqlParameter("@WetLifeTime", WetLifeTime));
                                command.Parameters.Add(new SqlParameter("@QRLength", QRLength));
                                command.Parameters.Add(new SqlParameter("@CUSTOMERID", CUSTOMERID));
                                command.Parameters.Add(new SqlParameter("@ENABLE", "Y"));
                                command.Parameters.Add(new SqlParameter("@addUserName", addUserName));
                                command.Parameters.Add(new SqlParameter("@addSystemDate", addSystemDate));
                                command.Parameters.Add(new SqlParameter("@addSystemTime", addSystemTime));
                                command.Parameters.Add(new SqlParameter("@editUserName", editUserName));
                                command.Parameters.Add(new SqlParameter("@editSystemDate", editSystemDate));
                                command.Parameters.Add(new SqlParameter("@editSystemTime", editSystemTime));
                                command.Parameters.Add(new SqlParameter("@Location", Location));
                                command.Parameters.Add(new SqlParameter("@Packaging", Packaging));
                                command.Parameters.Add(new SqlParameter("@ModelStart", ModelStart));
                                command.Parameters.Add(new SqlParameter("@ModelLength", ModelLength));
                                command.Parameters.Add(new SqlParameter("@DateStart", DateStart));
                                command.Parameters.Add(new SqlParameter("@DateLength", DateLength));
                                command.Parameters.Add(new SqlParameter("@SIDE", SIDE));
                                command.Parameters.Add(new SqlParameter("@Type", Type));
                                command.Parameters.Add(new SqlParameter("@Wet", Wet));
                                command.Parameters.Add(new SqlParameter("@Detail", Detail));

                                command.ExecuteNonQuery();

                            }


                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }


        public static void insertHistoryLog(string dbconLocal, string MASTERTEXT, string PART_NUM, string PART_ID, string CUST_PART_NUM,
            string PART_NAME, int QPACK, int WEIGHT, string UNIT, string STARTDATE,
            string ENDDATE, double DIFF, string CREATEBY, string CREATEDATE,
            string CREATETIME, string STATUS, string LOGMSG, string LOGSTAGE,
            string COMNAME, string REMARK, string PART_SERIAL)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {

                                command.CommandText = @"INSERT INTO TB_HISTORY_LOG (MASTERTEXT, PART_NUM, PART_ID, 
                                                        CUST_PART_NUM, PART_NAME, QPACK, WEIGHT, UNIT, STARTDATE, 
                                                        ENDDATE, DIFF, CREATEBY, CREATEDATE, CREATETIME, STATUS, 
                                                        LOGMSG, LOGSTAGE, COMNAME, REMARK, PART_SERIAL) 
                                                        VALUES (@MASTERTEXT,@PART_NUM,@PART_ID,@CUST_PART_NUM,@PART_NAME
                                                        ,@QPACK,@WEIGHT,@UNIT,@STARTDATE
                                                        ,@ENDDATE,@DIFF,@CREATEBY,@CREATEDATE, @CREATETIME, @STATUS
                                                        , @LOGMSG, @LOGSTAGE,@COMNAME,@REMARK,@PART_SERIAL)";


                                command.Parameters.Add(new SqlParameter("@MASTERTEXT", MASTERTEXT));
                                command.Parameters.Add(new SqlParameter("@PART_NUM", PART_NUM));
                                command.Parameters.Add(new SqlParameter("@PART_ID", PART_ID));
                                command.Parameters.Add(new SqlParameter("@CUST_PART_NUM", CUST_PART_NUM));
                                command.Parameters.Add(new SqlParameter("@PART_NAME", PART_NAME));
                                command.Parameters.Add(new SqlParameter("@QPACK", QPACK));
                                command.Parameters.Add(new SqlParameter("@WEIGHT", WEIGHT));
                                command.Parameters.Add(new SqlParameter("@UNIT", UNIT));
                                command.Parameters.Add(new SqlParameter("@STARTDATE", STARTDATE));
                                command.Parameters.Add(new SqlParameter("@ENDDATE", ENDDATE));
                                command.Parameters.Add(new SqlParameter("@DIFF", DIFF));
                                command.Parameters.Add(new SqlParameter("@CREATEBY", CREATEBY));
                                command.Parameters.Add(new SqlParameter("@CREATEDATE", CREATEDATE));
                                command.Parameters.Add(new SqlParameter("@CREATETIME", CREATETIME));
                                command.Parameters.Add(new SqlParameter("@STATUS", STATUS));
                                command.Parameters.Add(new SqlParameter("@LOGMSG", LOGMSG));
                                command.Parameters.Add(new SqlParameter("@LOGSTAGE", LOGSTAGE));
                                command.Parameters.Add(new SqlParameter("@COMNAME", COMNAME));
                                command.Parameters.Add(new SqlParameter("@REMARK", REMARK));
                                command.Parameters.Add(new SqlParameter("@PART_SERIAL", PART_SERIAL));


                                command.ExecuteNonQuery();

                            }


                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static void insertTT_KANBAN_H(string dbconLocal, string PART_NUM, string PART_NAME, string MODEL, string MODEL_CODE,
            string PART_ID, string CUST_ID, string CUST_PART_NUM, string CUST_PART_ID, string CUST_PART_NAME,
            string DESCRIPTION, string FRMLOCCODE, string CURLOCCODE, string NXTLOCCODE, string SHELF_NUM,
            int QPACK, string UNIT, string SERIAL, string QRKANBAN, string FRMSERIAL, string FRMQRKANBAN,
            string KANBANTYPE, string PRINTBY, string PRINTDATE, string PRINTTIME,
            string ENABLE, string CREATEBY, string CREATEDATE, string CREATETIME,
            string EDITBY, string EDITDATE, string EDITTIME,
            string REMARK1, string REMARK2, string REMARK3,
            string REMARK4, string REMARK5, int NUMBER1, int NUMBER2)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {

                                command.CommandText = @"INSERT INTO TT_KANBAN_H ([PART_NUM]
                                                      ,[PART_NAME]
                                                      ,[MODEL]
                                                      ,[MODEL_CODE]
                                                      ,[PART_ID]
                                                      ,[CUST_ID]
                                                      ,[CUST_PART_NUM]
                                                      ,[CUST_PART_ID]
                                                      ,[CUST_PART_NAME]
                                                      ,[DESCRIPTION]
                                                      ,[FRMLOCCODE]
                                                      ,[CURLOCCODE]
                                                      ,[NXTLOCCODE]
                                                      ,[SHELF_NUM]
                                                      ,[QPACK]
                                                      ,[UNIT]
                                                      ,[SERIAL]
                                                      ,[QRKANBAN]
                                                      ,[FRMSERIAL]
                                                      ,[FRMQRKANBAN]
                                                      ,[KANBANTYPE]
                                                      ,[PRINTBY]
                                                      ,[PRINTDATE]
                                                      ,[PRINTTIME]
                                                      ,[ENABLE]
                                                      ,[CREATEBY]
                                                      ,[CREATEDATE]
                                                      ,[CREATETIME]
                                                      ,[EDITBY]
                                                      ,[EDITDATE]
                                                      ,[EDITTIME]
                                                      ,[REMARK1]
                                                      ,[REMARK2]
                                                      ,[REMARK3]
                                                      ,[REMARK4]
                                                      ,[REMARK5]
                                                      ,[NUMBER1]
                                                      ,[NUMBER2]) 
                                                        VALUES (@PART_NUM,@PART_NAME,@MODEL,@MODEL_CODE,@PART_ID
                                                        ,@CUST_ID,@CUST_PART_NUM,@CUST_PART_ID,@CUST_PART_NAME
                                                        ,@DESCRIPTION,@FRMLOCCODE,@CURLOCCODE,@NXTLOCCODE
                                                        ,@SHELF_NUM,@QPACK,@UNIT,@SERIAL,@QRKANBAN
                                                        ,@FRMSERIAL,@FRMQRKANBAN,@KANBANTYPE
                                                        ,@PRINTBY,@PRINTDATE,@PRINTTIME,@ENABLE
                                                        ,@CREATEBY,@CREATEDATE, @CREATETIME
                                                        ,@EDITBY,@EDITDATE,@EDITTIME
                                                        ,@REMARK1,@REMARK2,@REMARK3,@REMARK4,@REMARK5
                                                        ,@NUMBER1,@NUMBER2)";


                                command.Parameters.Add(new SqlParameter("@PART_NUM", PART_NUM));
                                command.Parameters.Add(new SqlParameter("@PART_NAME", PART_NAME));
                                command.Parameters.Add(new SqlParameter("@MODEL", MODEL));
                                command.Parameters.Add(new SqlParameter("@MODEL_CODE", MODEL_CODE));
                                command.Parameters.Add(new SqlParameter("@PART_ID", PART_ID));
                                command.Parameters.Add(new SqlParameter("@CUST_ID", CUST_ID));
                                command.Parameters.Add(new SqlParameter("@CUST_PART_NUM", CUST_PART_NUM));
                                command.Parameters.Add(new SqlParameter("@CUST_PART_ID", CUST_PART_ID));
                                command.Parameters.Add(new SqlParameter("@CUST_PART_NAME", CUST_PART_NAME));
                                command.Parameters.Add(new SqlParameter("@DESCRIPTION", DESCRIPTION));
                                command.Parameters.Add(new SqlParameter("@FRMLOCCODE", FRMLOCCODE));
                                command.Parameters.Add(new SqlParameter("@CURLOCCODE", CURLOCCODE));
                                command.Parameters.Add(new SqlParameter("@NXTLOCCODE", NXTLOCCODE));
                                command.Parameters.Add(new SqlParameter("@SHELF_NUM", SHELF_NUM));
                                command.Parameters.Add(new SqlParameter("@QPACK", QPACK));
                                command.Parameters.Add(new SqlParameter("@UNIT", UNIT));
                                command.Parameters.Add(new SqlParameter("@SERIAL", SERIAL));
                                command.Parameters.Add(new SqlParameter("@QRKANBAN", QRKANBAN));
                                command.Parameters.Add(new SqlParameter("@FRMSERIAL", FRMSERIAL));
                                command.Parameters.Add(new SqlParameter("@FRMQRKANBAN", FRMQRKANBAN));
                                command.Parameters.Add(new SqlParameter("@KANBANTYPE", KANBANTYPE));
                                command.Parameters.Add(new SqlParameter("@PRINTBY", PRINTBY));
                                command.Parameters.Add(new SqlParameter("@PRINTDATE", PRINTDATE));
                                command.Parameters.Add(new SqlParameter("@PRINTTIME", PRINTTIME));
                                command.Parameters.Add(new SqlParameter("@ENABLE", ENABLE));
                                command.Parameters.Add(new SqlParameter("@CREATEBY", CREATEBY));
                                command.Parameters.Add(new SqlParameter("@CREATEDATE", CREATEDATE));
                                command.Parameters.Add(new SqlParameter("@CREATETIME", CREATETIME));
                                command.Parameters.Add(new SqlParameter("@EDITBY", EDITBY));
                                command.Parameters.Add(new SqlParameter("@EDITDATE", EDITDATE));
                                command.Parameters.Add(new SqlParameter("@EDITTIME", EDITTIME));
                                command.Parameters.Add(new SqlParameter("@REMARK1", REMARK1));
                                command.Parameters.Add(new SqlParameter("@REMARK2", REMARK2));
                                command.Parameters.Add(new SqlParameter("@REMARK3", REMARK3));
                                command.Parameters.Add(new SqlParameter("@REMARK4", REMARK4));
                                command.Parameters.Add(new SqlParameter("@REMARK5", REMARK5));
                                command.Parameters.Add(new SqlParameter("@NUMBER1", NUMBER1));
                                command.Parameters.Add(new SqlParameter("@NUMBER2", NUMBER2));

                                command.ExecuteNonQuery();

                            }


                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static void insertTT_KANBAN_L(string dbconLocal, int KBHROWID, string PART_NUM, string PART_NAME, string MODEL, string MODEL_CODE,
            string PART_ID, string DESCRIPTION, string SERIAL, string QRSERIAL, Int64 DRYTIME,
            string EXPIREDATE,
            string ENABLE, string CREATEBY, string CREATEDATE, string CREATETIME,
            string EDITBY, string EDITDATE, string EDITTIME,
            string REMARK1, string REMARK2, string REMARK3,
            string REMARK4, string REMARK5, int NUMBER1, int NUMBER2)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {

                                command.CommandText = @"INSERT INTO TT_KANBAN_L ([KBHROWID]
                                                      ,[PART_NUM]
                                                      ,[PART_NAME]
                                                      ,[MODEL]
                                                      ,[MODEL_CODE]
                                                      ,[PART_ID]
                                                      ,[DESCRIPTION]
                                                      ,[SERIAL]
                                                      ,[QRSERIAL]
                                                      ,[DRYTIME]
                                                      ,[EXPIREDATE]
                                                      ,[ENABLE]
                                                      ,[CREATEBY]
                                                      ,[CREATEDATE]
                                                      ,[CREATETIME]
                                                      ,[EDITBY]
                                                      ,[EDITDATE]
                                                      ,[EDITTIME]
                                                      ,[REMARK1]
                                                      ,[REMARK2]
                                                      ,[REMARK3]
                                                      ,[REMARK4]
                                                      ,[REMARK5]
                                                      ,[NUMBER1]
                                                      ,[NUMBER2]) 
                                                        VALUES (@KBHROWID,@PART_NUM,@PART_NAME,@MODEL,@MODEL_CODE,@PART_ID
                                                        ,@DESCRIPTION,@SERIAL,@QRSERIAL
                                                        ,@DRYTIME,@EXPIREDATE,@ENABLE                                                        
                                                        ,@CREATEBY,@CREATEDATE, @CREATETIME
                                                        ,@EDITBY,@EDITDATE,@EDITTIME
                                                        ,@REMARK1,@REMARK2,@REMARK3,@REMARK4,@REMARK5
                                                        ,@NUMBER1,@NUMBER2)";

                                command.Parameters.Add(new SqlParameter("@KBHROWID", KBHROWID));
                                command.Parameters.Add(new SqlParameter("@PART_NUM", PART_NUM));
                                command.Parameters.Add(new SqlParameter("@PART_NAME", PART_NAME));
                                command.Parameters.Add(new SqlParameter("@MODEL", MODEL));
                                command.Parameters.Add(new SqlParameter("@MODEL_CODE", MODEL_CODE));
                                command.Parameters.Add(new SqlParameter("@PART_ID", PART_ID));
                                command.Parameters.Add(new SqlParameter("@DESCRIPTION", DESCRIPTION));
                                command.Parameters.Add(new SqlParameter("@SERIAL", SERIAL));
                                command.Parameters.Add(new SqlParameter("@QRSERIAL", QRSERIAL));
                                command.Parameters.Add(new SqlParameter("@DRYTIME", DRYTIME));
                                command.Parameters.Add(new SqlParameter("@EXPIREDATE", EXPIREDATE));
                                command.Parameters.Add(new SqlParameter("@ENABLE", ENABLE));
                                command.Parameters.Add(new SqlParameter("@CREATEBY", CREATEBY));
                                command.Parameters.Add(new SqlParameter("@CREATEDATE", CREATEDATE));
                                command.Parameters.Add(new SqlParameter("@CREATETIME", CREATETIME));
                                command.Parameters.Add(new SqlParameter("@EDITBY", EDITBY));
                                command.Parameters.Add(new SqlParameter("@EDITDATE", EDITDATE));
                                command.Parameters.Add(new SqlParameter("@EDITTIME", EDITTIME));
                                command.Parameters.Add(new SqlParameter("@REMARK1", REMARK1));
                                command.Parameters.Add(new SqlParameter("@REMARK2", REMARK2));
                                command.Parameters.Add(new SqlParameter("@REMARK3", REMARK3));
                                command.Parameters.Add(new SqlParameter("@REMARK4", REMARK4));
                                command.Parameters.Add(new SqlParameter("@REMARK5", REMARK5));
                                command.Parameters.Add(new SqlParameter("@NUMBER1", NUMBER1));
                                command.Parameters.Add(new SqlParameter("@NUMBER2", NUMBER2));

                                command.ExecuteNonQuery();

                            }


                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static void insertTT_KANBAN_L(string dbconLocal, string PART_NUM, string PART_NAME, string MODEL, string MODEL_CODE,
            string PART_ID, string CUST_ID, string CUST_PART_NUM, string CUST_PART_ID, string CUST_PART_NAME,
            string DESCRIPTION, string FRMLOCCODE, string CURLOCCODE, string NXTLOCCODE, string SHELF_NUM,
            int QPACK, string UNIT, string SERIAL, string QRKANBAN, string FRMSERIAL, string FRMQRKANBAN,
            string KANBANTYPE, string PRINTBY, string PRINTDATE, string PRINTTIME,
            string ENABLE, string CREATEBY, string CREATEDATE, string CREATETIME,
            string EDITBY, string EDITDATE, string EDITTIME,
            string REMARK1, string REMARK2, string REMARK3,
            string REMARK4, string REMARK5, int NUMBER1, int NUMBER2)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {

                                command.CommandText = @"INSERT INTO TT_KANBAN_H ([PART_NUM]
                                                      ,[PART_NAME]
                                                      ,[MODEL]
                                                      ,[MODEL_CODE]
                                                      ,[PART_ID]
                                                      ,[CUST_ID]
                                                      ,[CUST_PART_NUM]
                                                      ,[CUST_PART_ID]
                                                      ,[CUST_PART_NAME]
                                                      ,[DESCRIPTION]
                                                      ,[FRMLOCCODE]
                                                      ,[CURLOCCODE]
                                                      ,[NXTLOCCODE]
                                                      ,[SHELF_NUM]
                                                      ,[QPACK]
                                                      ,[UNIT]
                                                      ,[SERIAL]
                                                      ,[QRKANBAN]
                                                      ,[FRMSERIAL]
                                                      ,[FRMQRKANBAN]
                                                      ,[KANBANTYPE]
                                                      ,[PRINTBY]
                                                      ,[PRINTDATE]
                                                      ,[PRINTTIME]
                                                      ,[ENABLE]
                                                      ,[CREATEBY]
                                                      ,[CREATEDATE]
                                                      ,[CREATETIME]
                                                      ,[EDITBY]
                                                      ,[EDITDATE]
                                                      ,[EDITTIME]
                                                      ,[REMARK1]
                                                      ,[REMARK2]
                                                      ,[REMARK3]
                                                      ,[REMARK4]
                                                      ,[REMARK5]
                                                      ,[NUMBER1]
                                                      ,[NUMBER2]) 
                                                        VALUES (@PART_NUM,@PART_NAME,@MODEL,@MODEL_CODE,@PART_ID
                                                        ,@CUST_ID,@CUST_PART_NUM,@CUST_PART_ID,@CUST_PART_NAME
                                                        ,@DESCRIPTION,@FRMLOCCODE,@CURLOCCODE,@NXTLOCCODE
                                                        ,@SHELF_NUM,@QPACK,@UNIT,@SERIAL,@QRKANBAN
                                                        ,@FRMSERIAL,@FRMQRKANBAN,@KANBANTYPE
                                                        ,@PRINTBY,@PRINTDATE,@PRINTTIME,@ENABLE
                                                        ,@CREATEBY,@CREATEDATE, @CREATETIME
                                                        ,@EDITBY,@EDITDATE,@EDITTIME
                                                        ,@REMARK1,@REMARK2,@REMARK3,@REMARK4,@REMARK5
                                                        ,@NUMBER1,@NUMBER2)";


                                command.Parameters.Add(new SqlParameter("@PART_NUM", PART_NUM));
                                command.Parameters.Add(new SqlParameter("@PART_NAME", PART_NAME));
                                command.Parameters.Add(new SqlParameter("@MODEL", MODEL));
                                command.Parameters.Add(new SqlParameter("@MODEL_CODE", MODEL_CODE));
                                command.Parameters.Add(new SqlParameter("@PART_ID", PART_ID));
                                command.Parameters.Add(new SqlParameter("@CUST_ID", CUST_ID));
                                command.Parameters.Add(new SqlParameter("@CUST_PART_NUM", CUST_PART_NUM));
                                command.Parameters.Add(new SqlParameter("@CUST_PART_ID", CUST_PART_ID));
                                command.Parameters.Add(new SqlParameter("@CUST_PART_NAME", CUST_PART_NAME));
                                command.Parameters.Add(new SqlParameter("@DESCRIPTION", DESCRIPTION));
                                command.Parameters.Add(new SqlParameter("@FRMLOCCODE", FRMLOCCODE));
                                command.Parameters.Add(new SqlParameter("@CURLOCCODE", CURLOCCODE));
                                command.Parameters.Add(new SqlParameter("@NXTLOCCODE", NXTLOCCODE));
                                command.Parameters.Add(new SqlParameter("@SHELF_NUM", SHELF_NUM));
                                command.Parameters.Add(new SqlParameter("@QPACK", QPACK));
                                command.Parameters.Add(new SqlParameter("@UNIT", UNIT));
                                command.Parameters.Add(new SqlParameter("@SERIAL", SERIAL));
                                command.Parameters.Add(new SqlParameter("@QRKANBAN", QRKANBAN));
                                command.Parameters.Add(new SqlParameter("@FRMSERIAL", FRMSERIAL));
                                command.Parameters.Add(new SqlParameter("@FRMQRKANBAN", FRMQRKANBAN));
                                command.Parameters.Add(new SqlParameter("@KANBANTYPE", KANBANTYPE));
                                command.Parameters.Add(new SqlParameter("@PRINTBY", PRINTBY));
                                command.Parameters.Add(new SqlParameter("@PRINTDATE", PRINTDATE));
                                command.Parameters.Add(new SqlParameter("@CREATETIME", PRINTTIME));
                                command.Parameters.Add(new SqlParameter("@ENABLE", ENABLE));
                                command.Parameters.Add(new SqlParameter("@CREATEBY", CREATEBY));
                                command.Parameters.Add(new SqlParameter("@CREATEDATE", CREATEDATE));
                                command.Parameters.Add(new SqlParameter("@CREATETIME", CREATETIME));
                                command.Parameters.Add(new SqlParameter("@EDITBY", EDITBY));
                                command.Parameters.Add(new SqlParameter("@EDITDATE", EDITDATE));
                                command.Parameters.Add(new SqlParameter("@EDITTIME", EDITTIME));
                                command.Parameters.Add(new SqlParameter("@REMARK1", REMARK1));
                                command.Parameters.Add(new SqlParameter("@REMARK2", REMARK2));
                                command.Parameters.Add(new SqlParameter("@REMARK3", REMARK3));
                                command.Parameters.Add(new SqlParameter("@REMARK4", REMARK4));
                                command.Parameters.Add(new SqlParameter("@REMARK5", REMARK5));
                                command.Parameters.Add(new SqlParameter("@NUMBER1", NUMBER1));
                                command.Parameters.Add(new SqlParameter("@NUMBER2", NUMBER2));

                                command.ExecuteNonQuery();

                            }


                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static void insertUser(string dbconLocal, string userID, string Username, string Password,
            string Permission, bool Status, string addSystemDate,
            string addSystemTime, string editSystemDate, string editSystemTime)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");
            string strStatus = string.Empty;

            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {

                                if (Status == true)
                                {
                                    strStatus = "Y";
                                }
                                else
                                {
                                    strStatus = "N";
                                }

                                command.CommandText = @"INSERT INTO TM_USER (USERID, NAME, PASSWORD, PERMISSION, ENABLE, CREATEDATE, CREATETIME, EDITDATE, EDITTIME) 
                                                        VALUES (@userID,@Username,@Password,@Permission,@Status,@addSystemDate,@addSystemTime,@editSystemDate,@editSystemTime)";


                                command.Parameters.Add(new SqlParameter("@userID", userID));
                                command.Parameters.Add(new SqlParameter("@Username", Username));
                                command.Parameters.Add(new SqlParameter("@Password", Password));
                                command.Parameters.Add(new SqlParameter("@Permission", Permission));
                                command.Parameters.Add(new SqlParameter("@Status", strStatus));
                                command.Parameters.Add(new SqlParameter("@addSystemDate", addSystemDate));
                                command.Parameters.Add(new SqlParameter("@addSystemTime", addSystemTime));
                                command.Parameters.Add(new SqlParameter("@editSystemDate", editSystemDate));
                                command.Parameters.Add(new SqlParameter("@editSystemTime", editSystemTime));

                                command.ExecuteNonQuery();

                            }


                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static void insertSetting(string dbconLocal, Int32 ModelNameX
      , Int32 ModelNameY
      , Int32 ModelNameFS
      , Int32 CustomerNameX
      , Int32 CustomerNameY
      , Int32 CustomerNameFS
      , Int32 CustomerCodeX
      , Int32 CustomerCodeY
      , Int32 CustomerCodeFS
      , Int32 QtyX
      , Int32 QtyY
      , Int32 QtyFS
      , Int32 UserNameX
      , Int32 UserNameY
      , Int32 UserNameFS
      , Int32 SerialNoX
      , Int32 SerialNoY
      , Int32 SerialNoFS
      , Int32 PartNoX
      , Int32 PartNoY
      , Int32 PartNoFS
      , Int32 CustomerPartNoX
      , Int32 CustomerPartNoY
      , Int32 CustomerPartNoFS
      , Int32 LocationX
      , Int32 LocationY
      , Int32 LocationFS
      , Int32 SIDEX
      , Int32 SIDEY
      , Int32 SIDEFS
      , Int32 DateX
      , Int32 DateY
      , Int32 DateFS
      , Int32 TimeX
      , Int32 TimeY
      , Int32 TimeFS
      , Int32 QRX
      , Int32 QRY
      , Int32 QRFS
      , Int32 DetailX
      , Int32 DetailY
      , Int32 DetailFS
      , string Username, string editSystemDate, string editSystemTime)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {


                                command.CommandText = @"INSERT INTO TM_SETTING ([ModelNameX] ,[ModelNameY] ,[ModelNameFS] ,[CustomerNameX] ,[CustomerNameY] ,[CustomerNameFS] ,[CustomerCodeX] ,[CustomerCodeY] ,[CustomerCodeFS] ,[QtyX] ,[QtyY] ,[QtyFS] ,[UserNameX] ,[UserNameY] ,[UserNameFS] ,[SerialNoX] ,[SerialNoY] ,[SerialNoFS] ,[PartNoX] ,[PartNoY] ,[PartNoFS] ,[CustomerPartNoX] ,[CustomerPartNoY] ,[CustomerPartNoFS] ,[LocationX] ,[LocationY] ,[LocationFS] ,[SIDEX] ,[SIDEY] ,[SIDEFS] ,[DateX] ,[DateY] ,[DateFS] ,[TimeX] ,[TimeY] ,[TimeFS] ,[QRX] ,[QRY] ,[QRFS], [DetailX], [DetailY], [DetailFS], EDITBY, EDITDATE, EDITTIME) 
                                                        VALUES (@ModelNameX,@ModelNameY,@ModelNameFS,
                                                                @CustomerNameX,@CustomerNameY,@CustomerNameFS,
                                                                @CustomerCodeX,@CustomerCodeY,@CustomerCodeFS,
                                                                @QtyX,@QtyY,@QtyFS,
                                                                @UserNameX,@UserNameY,@UserNameFS,
                                                                @SerialNoX,@SerialNoY,@SerialNoFS,
                                                                @PartNoX,@PartNoY,@PartNoFS,
                                                                @CustomerPartNoX,@CustomerPartNoY,@CustomerPartNoFS,
                                                                @LocationX,@LocationY,@LocationFS,
                                                                @SIDEX,@SIDEY,@SIDEFS,
                                                                @DateX,@DateY,@DateFS,
                                                                @TimeX,@TimeY,@TimeFS,
                                                                @QRX,@QRY,@QRFS,
                                                                @DetailX,@DetailY,@DetailFS,
                                                                @Username,@editSystemDate,@editSystemTime)";


                                command.Parameters.Add(new SqlParameter("@ModelNameX", ModelNameX));
                                command.Parameters.Add(new SqlParameter("@ModelNameY", ModelNameY));
                                command.Parameters.Add(new SqlParameter("@ModelNameFS", ModelNameFS));
                                command.Parameters.Add(new SqlParameter("@CustomerNameX", CustomerNameX));
                                command.Parameters.Add(new SqlParameter("@CustomerNameY", CustomerNameY));
                                command.Parameters.Add(new SqlParameter("@CustomerNameFS", CustomerNameFS));
                                command.Parameters.Add(new SqlParameter("@CustomerCodeX", CustomerCodeX));
                                command.Parameters.Add(new SqlParameter("@CustomerCodeY", CustomerCodeY));
                                command.Parameters.Add(new SqlParameter("@CustomerCodeFS", CustomerCodeFS));
                                command.Parameters.Add(new SqlParameter("@QtyX", QtyX));
                                command.Parameters.Add(new SqlParameter("@QtyY", QtyY));
                                command.Parameters.Add(new SqlParameter("@QtyFS", QtyFS));
                                command.Parameters.Add(new SqlParameter("@UserNameX", UserNameX));
                                command.Parameters.Add(new SqlParameter("@UserNameY", UserNameY));
                                command.Parameters.Add(new SqlParameter("@UserNameFS", UserNameFS));
                                command.Parameters.Add(new SqlParameter("@SerialNoX", SerialNoX));
                                command.Parameters.Add(new SqlParameter("@SerialNoY", SerialNoY));
                                command.Parameters.Add(new SqlParameter("@SerialNoFS", SerialNoFS));
                                command.Parameters.Add(new SqlParameter("@PartNoX", PartNoX));
                                command.Parameters.Add(new SqlParameter("@PartNoY", PartNoY));
                                command.Parameters.Add(new SqlParameter("@PartNoFS", PartNoFS));
                                command.Parameters.Add(new SqlParameter("@CustomerPartNoX", CustomerPartNoX));
                                command.Parameters.Add(new SqlParameter("@CustomerPartNoY", CustomerPartNoY));
                                command.Parameters.Add(new SqlParameter("@CustomerPartNoFS", CustomerPartNoFS));
                                command.Parameters.Add(new SqlParameter("@LocationX", LocationX));
                                command.Parameters.Add(new SqlParameter("@LocationY", LocationY));
                                command.Parameters.Add(new SqlParameter("@LocationFS", LocationFS));
                                command.Parameters.Add(new SqlParameter("@SIDEX", SIDEX));
                                command.Parameters.Add(new SqlParameter("@SIDEY", SIDEY));
                                command.Parameters.Add(new SqlParameter("@SIDEFS", SIDEFS));
                                command.Parameters.Add(new SqlParameter("@DateX", DateX));
                                command.Parameters.Add(new SqlParameter("@DateY", DateY));
                                command.Parameters.Add(new SqlParameter("@DateFS", DateFS));
                                command.Parameters.Add(new SqlParameter("@TimeX", TimeX));
                                command.Parameters.Add(new SqlParameter("@TimeY", TimeY));
                                command.Parameters.Add(new SqlParameter("@TimeFS", TimeFS));
                                command.Parameters.Add(new SqlParameter("@QRX", QRX));
                                command.Parameters.Add(new SqlParameter("@QRY", QRY));
                                command.Parameters.Add(new SqlParameter("@QRFS", QRFS));
                                command.Parameters.Add(new SqlParameter("@DetailX", DetailX));
                                command.Parameters.Add(new SqlParameter("@DetailY", DetailY));
                                command.Parameters.Add(new SqlParameter("@DetailFS", DetailFS));

                                command.Parameters.Add(new SqlParameter("@Username", Username));
                                command.Parameters.Add(new SqlParameter("@editSystemDate", editSystemDate));
                                command.Parameters.Add(new SqlParameter("@editSystemTime", editSystemTime));

                                command.ExecuteNonQuery();

                            }

                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static void insertSettingPLC(string dbconLocal, string IP
      , string Port
      , bool TUse
      , bool CSPUse
      , bool CDUse
      , string Username, string editSystemDate, string editSystemTime, string ProcessNo, bool ReInputUse)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {


                                command.CommandText = @"INSERT INTO TM_SETTING_PLC ([IP] ,[Port] ,[TUse] ,[CSPUse], [CDUse], EDITBY, EDITDATE, EDITTIME, ProcessNo, ReInputUse) 
                                                        VALUES (@IP,@Port,@TUse,
                                                                @CSPUse, @CDUse,
                                                                @Username,@editSystemDate,@editSystemTime,@ProcessNo,@ReInputUse)";


                                command.Parameters.Add(new SqlParameter("@IP", IP));
                                command.Parameters.Add(new SqlParameter("@Port", Port));
                                command.Parameters.Add(new SqlParameter("@TUse", TUse));
                                command.Parameters.Add(new SqlParameter("@CSPUse", CSPUse));
                                command.Parameters.Add(new SqlParameter("@CDUse", CDUse));
                                command.Parameters.Add(new SqlParameter("@Username", Username));
                                command.Parameters.Add(new SqlParameter("@editSystemDate", editSystemDate));
                                command.Parameters.Add(new SqlParameter("@editSystemTime", editSystemTime));
                                command.Parameters.Add(new SqlParameter("@ProcessNo", ProcessNo));
                                command.Parameters.Add(new SqlParameter("@ReInputUse", ReInputUse));

                                command.ExecuteNonQuery();

                            }

                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static void insertCustomer(string dbconLocal, string customerID, string CustomerName, string ENABLE,
            string userNameAdd, string addSystemDate,
            string addSystemTime, string userNameEdit, string editSystemDate, string editSystemTime)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");

            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {


                                command.CommandText = @"INSERT INTO TM_CUSTOMER (CUSTOMERID, CUSTOMER, ENABLE, CREATEBY, CREATEDATE, CREATETIME, EDITBY, EDITDATE, EDITTIME) 
                                                        VALUES (@customerID,@CustomerName,@ENABLE,@userNameAdd,@addSystemDate,@addSystemTime,@userNameEdit,@editSystemDate,@editSystemTime)";


                                command.Parameters.Add(new SqlParameter("@customerID", customerID));
                                command.Parameters.Add(new SqlParameter("@CustomerName", CustomerName));
                                command.Parameters.Add(new SqlParameter("@ENABLE", ENABLE));
                                command.Parameters.Add(new SqlParameter("@userNameAdd", userNameAdd));
                                command.Parameters.Add(new SqlParameter("@addSystemDate", addSystemDate));
                                command.Parameters.Add(new SqlParameter("@addSystemTime", addSystemTime));
                                command.Parameters.Add(new SqlParameter("@userNameEdit", userNameEdit));
                                command.Parameters.Add(new SqlParameter("@editSystemDate", editSystemDate));
                                command.Parameters.Add(new SqlParameter("@editSystemTime", editSystemTime));

                                command.ExecuteNonQuery();

                            }


                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static void insertPartFile(string dbconLocal, string ROWID, string PartNO, byte[] PhotoSpec1, byte[] PhotoSpec2)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            DataTable modt = new DataTable("MoniData");


            using (connection = new SqlConnection(dbconLocal))
            {
                try
                {
                    connection.Open();

                    using (var transaction = connection.BeginTransaction())
                    {
                        try
                        {

                            using (command = new SqlCommand() { Connection = connection, Transaction = transaction })
                            {

                                if (PhotoSpec1 != null && PhotoSpec2 != null)
                                {
                                    command.CommandText = @"INSERT INTO TM_PARTS_FILES (MPROWID, PART_NUM, FILE1, FILE2) 
                                                        VALUES (@ROWID,@PartNO,@PhotoSpec1,@PhotoSpec2)";

                                    command.Parameters.Add(new SqlParameter("@ROWID", ROWID));
                                    command.Parameters.Add(new SqlParameter("@PartNO", PartNO));
                                    command.Parameters.Add(new SqlParameter("@PhotoSpec1", PhotoSpec1));
                                    command.Parameters.Add(new SqlParameter("@PhotoSpec2", PhotoSpec2));

                                    command.ExecuteNonQuery();
                                }

                                else if (PhotoSpec1 != null && PhotoSpec2 == null)
                                {
                                    command.CommandText = @"INSERT INTO TM_PARTS_FILES (MPROWID, PART_NUM, FILE1) 
                                                        VALUES (@ROWID,@PartNO,@PhotoSpec1)";

                                    command.Parameters.Add(new SqlParameter("@ROWID", ROWID));
                                    command.Parameters.Add(new SqlParameter("@PartNO", PartNO));
                                    command.Parameters.Add(new SqlParameter("@PhotoSpec1", PhotoSpec1));

                                    command.ExecuteNonQuery();
                                }

                                else if (PhotoSpec1 == null && PhotoSpec2 != null)
                                {
                                    command.CommandText = @"INSERT INTO TM_PARTS_FILES (MPROWID, PART_NUM, FILE2) 
                                                        VALUES (@ROWID,@PartNO,@PhotoSpec2)";

                                    command.Parameters.Add(new SqlParameter("@ROWID", ROWID));
                                    command.Parameters.Add(new SqlParameter("@PartNO", PartNO));
                                    command.Parameters.Add(new SqlParameter("@PhotoSpec2", PhotoSpec2));

                                    command.ExecuteNonQuery();
                                }

                                else if (PhotoSpec1 == null && PhotoSpec2 == null)
                                {
                                    command.CommandText = @"INSERT INTO TM_PARTS_FILES (MPROWID, PART_NUM) 
                                                        VALUES (@ROWID,@PartNO)";

                                    command.Parameters.Add(new SqlParameter("@ROWID", ROWID));
                                    command.Parameters.Add(new SqlParameter("@PartNO", PartNO));

                                    command.ExecuteNonQuery();
                                }


                            }


                            transaction.Commit();

                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public static bool GetDataFromTB(string dbconLocal, string tableName, ref DataTable modt)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;

                        command.CommandText = "SELECT MODEL, PARTID, PART_NUM, PART_NAME, CUSTOMERID, ROWID FROM " + tableName + " order by MODEL;";
                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBsetting(string dbconLocal, string tableName, ref DataTable modt)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;

                        command.CommandText = "SELECT [ROWID] ,[ModelNameX] ,[ModelNameY] ,[ModelNameFS] ,[CustomerNameX] ,[CustomerNameY] ,[CustomerNameFS] ,[CustomerCodeX] ,[CustomerCodeY] ,[CustomerCodeFS] ,[QtyX] ,[QtyY] ,[QtyFS] ,[UserNameX] ,[UserNameY] ,[UserNameFS] ,[SerialNoX] ,[SerialNoY] ,[SerialNoFS] ,[PartNoX] ,[PartNoY] ,[PartNoFS] ,[CustomerPartNoX] ,[CustomerPartNoY] ,[CustomerPartNoFS] ,[LocationX] ,[LocationY] ,[LocationFS] ,[SIDEX] ,[SIDEY] ,[SIDEFS] ,[DateX] ,[DateY] ,[DateFS] ,[TimeX] ,[TimeY] ,[TimeFS] ,[QRX] ,[QRY] ,[QRFS], [DetailX], [DetailY], [DetailFS] FROM " + tableName + " ;";
                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBsettingPLC(string dbconLocal, string tableName, ref DataTable modt)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;

                        command.CommandText = "SELECT [IP] ,[Port] ,[TUse] ,[CSPUse], [CDUse], [ProcessNo], [ReInputUse] FROM " + tableName + " ;";
                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBserialKanban(string dbconLocal, string tableName, ref DataTable modt, string strComNo, string kanban)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;

                        command.CommandText = "SELECT MAX(SUBSTRING(SERIAL,4,14)) as MaxSerial FROM " + tableName + " WHERE SUBSTRING(SERIAL,6,8) = '" + DateTime.Now.ToString("yyyyMMdd") + "' and SUBSTRING(SERIAL,4,2) = '" + strComNo + "' and REMARK3 <> 'Cancel' and FRMQRKANBAN = '" + kanban + "'; ";
                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBserial(string dbconLocal, string tableName, ref DataTable modt, string strComNo)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;

                        //command.CommandText = "SELECT MAX(SUBSTRING(SERIAL,4,14)) as MaxSerial FROM " + tableName + " WHERE SUBSTRING(SERIAL,6,8) = '" + DateTime.Now.ToString("yyyyMMdd") + "' and SUBSTRING(SERIAL,4,2) = '" + strComNo + "' and REMARK3 <> 'Cancel' ; ";

                        command.CommandText = "SELECT MAX(SUBSTRING(SERIAL,4,14)) as MaxSerial FROM " + tableName + " WHERE SUBSTRING(SERIAL,6,8) = '" + DateTime.Now.ToString("yyyyMMdd") + "' and SUBSTRING(SERIAL,4,2) = '" + strComNo + "' ; ";

                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBCustomerMaster(string dbconLocal, string tableName, ref DataTable modt)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;

                        command.CommandText = "SELECT CUSTOMERID, CUSTOMER FROM " + tableName + " order by CUSTOMERID;";
                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBUser(string dbconLocal, string tableName, ref DataTable modt)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;

                        command.CommandText = "SELECT USERID, NAME, PERMISSION FROM " + tableName + " order by USERID;";
                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBCustomer(string dbconLocal, string tableName, ref DataTable modt)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;

                        command.CommandText = "SELECT CUSTOMERID, CUSTOMER FROM " + tableName + " order by CUSTOMERID;";
                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }


        public static bool GetDataFromTBSelect(string dbconLocal, string tableName, ref DataTable modt, string selectModel, string partno)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;

                        command.CommandText = "SELECT p.[ROWID] ,p.[PARTID] ,p.[MODEL] ,p.[MODEL_CODE] ,p.[PART_NAME] ,p.[CUST_PART_NAME] ,p.[PART_NUM] ,p.[CUST_PART_NUM] ,p.[QPACK] ,p.[CTIME] ,p.[DRYTIME] ,p.[WETTIME] ,p.[QRLEN] ,p.[CUSTOMERID] ,p.[ENABLE] ,p.[CREATEBY] ,p.[CREATEDATE] ,p.[CREATETIME] ,p.[EDITBY] ,p.[EDITDATE] ,p.[EDITTIME] ,p.[REMARK1] ,p.[REMARK2] ,p.[REMARK3] ,p.[REMARK4] ,p.[REMARK5] ,p.[NUMBER1] ,p.[NUMBER2] ,pf.[FILE1] ,pf.[FILE2] ,p.[SIDE], p.[TYPE], p.[WET_TYPE]  FROM " + tableName + " as p left join TM_PARTS_FILES as pf on p.[ROWID] = pf.[MPROWID] and p.[PART_NUM] = pf.[PART_NUM] where p.ROWID = " + Convert.ToInt32(selectModel) + " and p.[PART_NUM] = '" + partno + "';";
                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBHistoryOKSelect(string dbconLocal, string tableName, ref DataTable modt, Int32 ProductStart, Int32 ProductTo, Int32 PrintStart, Int32 PrintTo, string PartID, string PartNO, string CustomerPartID, string CustomerPartNO, string KBSerial, string PartSerial)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;
                        command.CommandText = "SELECT H.[PART_ID] ,H.[PART_NAME] ,H.[PART_NUM] ,H.[CUST_PART_NUM] ,H.[MODEL] ,H.[CUST_ID] ,H.[QPACK] ,H.[SERIAL] as [1 WAY SERIAL],H.[FRMSERIAL] as [BEFORE KB SERIAL] ,H.[CURLOCCODE] ,H.[PRINTBY] ,H.[PRINTDATE] ,H.[PRINTTIME] ,L.[DRYTIME] as [MFG DATE],L.[EXPIREDATE] as [EXPIRE DATE],L.[QRSERIAL] as [PART SERIAL], H.[REMARK1] as [PACKAGE TYPE], H.[REMARK4] as [QR Code 2], H.[MODEL_CODE] as [MODEL CODE], H.[REMARK2] as [SIDE], H.[FRMQRKANBAN] as [KANBAN]  FROM " + tableName + " as H left join TT_KANBAN_L as L on H.[KBHROWID] = L.[KBHROWID] where L.[DRYTIME] >= " + ProductStart + " and L.[DRYTIME] <= " + ProductTo + " and convert(int,H.[PRINTDATE]) >= " + PrintStart + " and convert(int,H.[PRINTDATE]) <= " + PrintTo + " and H.[REMARK3] <> 'Cancel' and L.[REMARK3] <> 'Cancel' and H.[REMARK3] <> 'Delete' and L.[REMARK3] <> 'Delete' and L.[REMARK3] <> 'NG' ";

                        if (PartID != string.Empty)
                        {
                            command.CommandText = command.CommandText + " and H.[PART_ID] = '" + PartID + "'";
                        }
                        if (PartNO != string.Empty)
                        {
                            command.CommandText = command.CommandText + " and H.[PART_NUM] = '" + PartNO + "'";
                        }
                        if (CustomerPartID != string.Empty)
                        {
                            command.CommandText = command.CommandText + " and H.[CUST_ID] = '" + CustomerPartID + "'";
                        }
                        if (CustomerPartNO != string.Empty)
                        {
                            command.CommandText = command.CommandText + " and H.[CUST_PART_NUM] = '" + CustomerPartNO + "'";
                        }
                        if (KBSerial != string.Empty)
                        {
                            command.CommandText = command.CommandText + " and H.[SERIAL] = '" + KBSerial + "'";
                        }
                        if (PartSerial != string.Empty)
                        {
                            command.CommandText = command.CommandText + " and L.[QRSERIAL] = '" + PartSerial + "'";
                        }

                        command.CommandText = command.CommandText + " order by convert(int,H.[PRINTDATE]) asc, convert(int,H.[PRINTTIME]) asc;";
                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBHistoryReturnSelect(string dbconLocal, string tableName, ref DataTable modt, Int32 ProductStart, Int32 ProductTo, Int32 DeliveryStart, Int32 DeliveryTo, string PartID, string PartNO, string CustomerPartID, string CustomerPartNO, string KBSerial, string PartSerial, string PKLNO)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;
                        //command.CommandText = "SELECT H.[PART_ID] ,H.[PART_NAME] ,H.[PART_NUM] ,H.[CUST_PART_NUM] ,H.[MODEL] ,H.[CUST_ID] ,H.[QPACK] ,H.[SERIAL] as [1 WAY SERIAL],H.[FRMSERIAL] as [BEFORE KB SERIAL] ,H.[CURLOCCODE] ,H.[PRINTBY] ,H.[PRINTDATE] ,H.[PRINTTIME] ,L.[DRYTIME] as [MFG DATE],L.[EXPIREDATE] as [EXPIRE DATE],L.[QRSERIAL] as [PART SERIAL], H.[REMARK1] as [PACKAGE TYPE], H.[REMARK4] as [QR Code 2], H.[MODEL_CODE] as [MODEL CODE], H.[REMARK2] as [SIDE], H.[FRMQRKANBAN] as [KANBAN]  FROM " + tableName + " as H left join TT_KANBAN_L as L on H.[KBHROWID] = L.[KBHROWID] where L.[DRYTIME] >= " + ProductStart + " and L.[DRYTIME] <= " + ProductTo + " and convert(int,H.[PRINTDATE]) >= " + PrintStart + " and convert(int,H.[PRINTDATE]) <= " + PrintTo + " and H.[REMARK3] <> 'Cancel' and L.[REMARK3] <> 'Cancel' and H.[REMARK3] <> 'Delete' and L.[REMARK3] <> 'Delete' and L.[REMARK3] <> 'NG' ";

                        command.CommandText = "SELECT H.[PART_ID] ,H.[PART_NAME] ,H.[PART_NUM] ,H.[CUST_PART_NUM] " +
                            ",H.[MODEL] ,H.[CUST_ID] ,H.[QPACK] ,H.[SERIAL] as [1 WAY SERIAL]" +
                            ",H.[FRMSERIAL] as [BEFORE KB SERIAL] ,H.[CURLOCCODE] ,H.[PRINTBY] " +
                            ",H.[PRINTDATE] ,H.[PRINTTIME] ,L.[DRYTIME] as [MFG DATE]" +
                            ",L.[EXPIREDATE] as [EXPIRE DATE],L.[QRSERIAL] as [PART SERIAL]" +
                            ", H.[REMARK1] as [PACKAGE TYPE], C.[PKL_NO] as [Customer Order]" +
                            ", C.[CUST_SERIAL] as [Kanban ลูกค้า], C.[CUST_PART] as [Cust Part]" +
                            ", C.[PART_ID] as [Part ID], C.[PACKING_DATE] as [DELIVERY DATE]" +
                            ", C.[PACKING_TIME] as [DELIVERY TIME], C.[PACKING_BY] as [DELIVERY BY]  FROM "
                            + tableName + " as H left join TT_KANBAN_L as L on H.[KBHROWID] = L.[KBHROWID] " +
                            "left join TT_CHECK_PROCESS as C on H.[QRKANBAN] COLLATE DATABASE_DEFAULT = C.[QRKANBAN] COLLATE DATABASE_DEFAULT"
                            + " where L.[DRYTIME] >= " + ProductStart + " and L.[DRYTIME] <= " + ProductTo
                            + " and convert(int,C.[PACKING_DATE]) >= " + DeliveryStart +
                            " and convert(int,C.[PACKING_DATE]) <= " + DeliveryTo + 
                            " and H.[REMARK3] <> 'Cancel' and L.[REMARK3] <> 'Cancel' " +
                            "and H.[REMARK3] <> 'Delete' and L.[REMARK3] <> 'Delete' and L.[REMARK3] <> 'NG' ";



                        if (PartID != string.Empty)
                        {
                            command.CommandText = command.CommandText + " and H.[PART_ID] = '" + PartID + "'";
                        }
                        if (PartNO != string.Empty)
                        {
                            command.CommandText = command.CommandText + " and H.[PART_NUM] = '" + PartNO + "'";
                        }
                        if (CustomerPartID != string.Empty)
                        {
                            command.CommandText = command.CommandText + " and H.[CUST_ID] = '" + CustomerPartID + "'";
                        }
                        if (CustomerPartNO != string.Empty)
                        {
                            command.CommandText = command.CommandText + " and H.[CUST_PART_NUM] = '" + CustomerPartNO + "'";
                        }
                        if (KBSerial != string.Empty)
                        {
                            command.CommandText = command.CommandText + " and H.[SERIAL] = '" + KBSerial + "'";
                        }
                        if (PartSerial != string.Empty)
                        {
                            command.CommandText = command.CommandText + " and L.[QRSERIAL] = '" + PartSerial + "'";
                        }
                        if (PKLNO != string.Empty)
                        {
                            command.CommandText = command.CommandText + " and C.[PKL_NO] = '" + PKLNO + "'";
                        }

                        command.CommandText = command.CommandText + " order by convert(int,C.[PACKING_DATE]) asc, convert(int,C.[PACKING_TIME]) asc;";
                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBHistoryDeleteSelect(string dbconLocal, string tableName, ref DataTable modt, Int32 ProductStart, Int32 ProductTo, Int32 PrintStart, Int32 PrintTo, string KBSerial)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;
                        command.CommandText = "SELECT H.[PART_ID] ,H.[KBHROWID], H.[PART_NAME] ,H.[PART_NUM] ,H.[CUST_PART_NUM] ,H.[MODEL] ,H.[CUST_ID] ,H.[QPACK] ,H.[SERIAL] as [1 WAY SERIAL],H.[FRMSERIAL] as [BEFORE KB SERIAL] ,H.[CURLOCCODE] ,H.[PRINTBY] ,H.[PRINTDATE] ,H.[PRINTTIME] ,L.[DRYTIME] as [MFG DATE],L.[EXPIREDATE] as [EXPIRE DATE],L.[QRSERIAL] as [PART SERIAL], H.[REMARK1] as [PACKAGE TYPE], H.[REMARK4] as [QR Code 2], H.[MODEL_CODE] as [MODEL CODE], H.[REMARK2] as [SIDE], H.[FRMQRKANBAN] as [KANBAN], H.[QRKANBAN] as [QRKANBAN]  FROM " + tableName + " as H left join TT_KANBAN_L as L on H.[KBHROWID] = L.[KBHROWID] where L.[DRYTIME] >= " + ProductStart + " and L.[DRYTIME] <= " + ProductTo + " and convert(int,H.[PRINTDATE]) >= " + PrintStart + " and convert(int,H.[PRINTDATE]) <= " + PrintTo + " and H.[REMARK3] <> 'Cancel' and L.[REMARK3] <> 'Cancel' and H.[REMARK3] <> 'Delete' and L.[REMARK3] <> 'Delete' and L.[REMARK3] <> 'NG' ";


                        if (KBSerial != string.Empty)
                        {
                            command.CommandText = command.CommandText + " and H.[SERIAL] = '" + KBSerial + "'";
                        }


                        command.CommandText = command.CommandText + " order by convert(int,H.[PRINTDATE]) asc, convert(int,H.[PRINTTIME]) asc;";
                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBHistoryNGSelect(string dbconLocal, string tableName, ref DataTable modt, Int32 Start, Int32 To, string PartID, string PartNO, string CustomerPartNO, string PartSerial)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;
                        //command.CommandText = "SELECT [PART_ID] as [PART ID] ,[PART_NUM] as [PART NUMBER] ,[CUST_PART_NUM] as [CUSTOMER PART NUMBER], [PART_NAME] as [PART NAME] ,[QPACK] ,[LOGMSG] as [NG MESSEGE],[CREATEBY] as [USER ID] ,[CREATEDATE] as [DATE] ,[CREATETIME] as [TIME]  FROM " + tableName + " where convert(int,[CREATEDATE]) >= " + Start + " and convert(int,[CREATEDATE]) <= " + To + " and substring([STATUS],1,2) = 'NG' ";
                        command.CommandText = "SELECT [PART_ID] as [PART ID] ,[PART_NUM] as [PART NUMBER] ,[CUST_PART_NUM] as [CUSTOMER PART NUMBER], [PART_NAME] as [PART NAME] ,[PART_SERIAL] as [PART SERIAL] ,[LOGMSG] as [NG MESSEGE],[CREATEBY] as [USER ID] ,[CREATEDATE] as [DATE] ,[CREATETIME] as [TIME]  FROM " + tableName + " where convert(int,[CREATEDATE]) >= " + Start + " and convert(int,[CREATEDATE]) <= " + To + " and substring([STATUS],1,2) = 'NG' ";

                        if (PartID != string.Empty)
                        {
                            command.CommandText = command.CommandText + " and [PART_ID] = '" + PartID + "'";
                        }
                        if (PartNO != string.Empty)
                        {
                            command.CommandText = command.CommandText + " and [PART_NUM] = '" + PartNO + "'";
                        }
                        if (CustomerPartNO != string.Empty)
                        {
                            command.CommandText = command.CommandText + " and [CUST_PART_NUM] = '" + CustomerPartNO + "'";
                        }
                        if (PartSerial != string.Empty)
                        {
                            command.CommandText = command.CommandText + " and [PART_SERIAL] = '" + PartSerial + "'";
                        }


                        command.CommandText = command.CommandText + " order by convert(int,[CREATEDATE]) asc, convert(int,[CREATETIME]) asc ;";
                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBPartNoSelect(string dbconLocal, string tableName, ref DataTable modt, string partno)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;

                        command.CommandText = "SELECT p.[ROWID] ,p.[PARTID] ,p.[MODEL] ,p.[MODEL_CODE] ,p.[PART_NAME] ,p.[CUST_PART_NAME] ,p.[PART_NUM] ,p.[CUST_PART_NUM] ,p.[QPACK] ,p.[CTIME] ,p.[DRYTIME] ,p.[WETTIME] ,p.[QRLEN] ,p.[CUSTOMERID] ,p.[ENABLE] ,p.[CREATEBY] ,p.[CREATEDATE] ,p.[CREATETIME] ,p.[EDITBY] ,p.[EDITDATE] ,p.[EDITTIME] ,p.[REMARK1] ,p.[REMARK2] ,p.[REMARK3] ,p.[REMARK4] ,p.[REMARK5] ,p.[NUMBER1] ,p.[NUMBER2] ,pf.[FILE1] ,pf.[FILE2] ,p.[SIDE], p.[TYPE], p.[WET_TYPE]  FROM " + tableName + " as p left join TM_PARTS_FILES as pf on p.[ROWID] = pf.[MPROWID] and p.[PART_NUM] = pf.[PART_NUM] where p.[PART_NUM] = '" + partno + "';";
                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBKanbanHSelect(string dbconLocal, string tableName, ref DataTable modt, string SERIAL)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;

                        command.CommandText = "SELECT [PART_NUM],[PART_NAME],[MODEL],[MODEL_CODE],[PART_ID],[CUST_ID],[CUST_PART_NUM],[CUST_PART_ID],[CUST_PART_NAME],[DESCRIPTION],[FRMLOCCODE],[CURLOCCODE],[NXTLOCCODE],[SHELF_NUM],[QPACK],[UNIT],[SERIAL],[QRKANBAN],[FRMSERIAL],[FRMQRKANBAN],[KANBANTYPE],[PRINTBY],[PRINTDATE],[PRINTTIME],[REMARK1],[REMARK2],[REMARK5] FROM " + tableName + " where [SERIAL] = '" + SERIAL + "'; ";

                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBKanbanLSelect(string dbconLocal, string tableName, ref DataTable modt, string SERIAL)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;

                        command.CommandText = "SELECT [SERIAL] FROM " + tableName + " where [QRSERIAL] = '" + SERIAL + "'; ";

                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBUserSelect(string dbconLocal, string tableName, ref DataTable modt, string selectUser)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;

                        command.CommandText = "SELECT [ROWID] ,[USERID] ,[NAME] ,[PASSWORD] ,[PERMISSION] ,[ENABLE] FROM " + tableName + " where USERID = N'" + selectUser + "' and ([ENABLE] = '1' or [ENABLE] = 'Y');";
                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBUserSelectAll(string dbconLocal, string tableName, ref DataTable modt, string selectUser)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;

                        command.CommandText = "SELECT [ROWID] ,[USERID] ,[NAME] ,[PASSWORD] ,[PERMISSION] ,[ENABLE] FROM " + tableName + " where USERID = N'" + selectUser + "';";
                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBCustomerSelect(string dbconLocal, string tableName, ref DataTable modt, string selectCustomer)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;

                        command.CommandText = "SELECT [ROWID] ,[CUSTOMERID] ,[CUSTOMER] FROM " + tableName + " where CUSTOMERID = '" + selectCustomer + "';";
                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBTT_KANBAN_HSelect_Finish(string dbconLocal, string tableName, ref DataTable modt, string kanban)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;

                        if (kanban != string.Empty)
                        {
                            command.CommandText = "SELECT TOP(1) [FRMQRKANBAN], [REMARK3], [KBHROWID], [CREATEDATE] FROM " + tableName
                                + " where [FRMQRKANBAN] = '" + kanban + "' and [REMARK3] <> 'Cancel'"
                                + " order by [EDITDATE] desc, [EDITTIME] desc;";
                        }
                        else
                        {
                            command.CommandText = "SELECT TOP(1) [FRMQRKANBAN], [REMARK3], [KBHROWID], [CREATEDATE] FROM " + tableName
                                + " where [REMARK3] <> 'Cancel' order by [EDITDATE] desc, [EDITTIME] desc;";

                        }

                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBTT_KANBAN_HSelect_Status(string dbconLocal, string tableName, ref DataTable modt)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;


                        command.CommandText = "SELECT TOP(1) [FRMQRKANBAN], [REMARK3], [KBHROWID], [CREATEDATE] FROM " + tableName
                            + " where (REMARK3 = 'Packing' or REMARK3 = 'Printed') and CREATEDATE >= '20230727'"
                            + " order by [CREATEDATE] desc, [CREATETIME] desc;";


                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBTT_KANBAN_HSelect_StatusTop1(string dbconLocal, string tableName, ref DataTable modt)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;


                        command.CommandText = "SELECT TOP(1) [FRMQRKANBAN], [REMARK3], [KBHROWID], [CREATEDATE] FROM " + tableName
                            + " order by [EDITDATE] desc, [EDITTIME] desc;";


                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBTT_KANBAN_HSelect_Finish_Top(string dbconLocal, string tableName, ref DataTable modt, string kanban)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;
                        command.CommandText = "SELECT TOP(1) [FRMQRKANBAN], [REMARK3], [KBHROWID], [CREATEDATE] FROM " + tableName
                            + " where [FRMQRKANBAN] <> '" + kanban + "' order by [CREATEDATE] desc, [CREATETIME] desc;";

                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBTT_KANBAN_HSelect_Hold(string dbconLocal, string tableName, ref DataTable modt)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;

                        //command.CommandText = "SELECT [FRMQRKANBAN], [REMARK3], [KBHROWID], [CREATEDATE] FROM " + tableName + " where [REMARK3] = 'HoldPrinted' or [REMARK3] = 'HoldPacking' group by FRMQRKANBAN order by [CREATEDATE] desc, [CREATETIME] desc;";

                        command.CommandText = "SELECT [FRMQRKANBAN] FROM " + tableName + " where [REMARK3] = 'HoldPrinted' or [REMARK3] = 'HoldPacking' group by FRMQRKANBAN order by [FRMQRKANBAN] ;";

                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        //public static bool GetDataFromTBTT_KANBAN_HSelect_Cancel(string dbconLocal, string tableName, ref DataTable modt, string Kanban)
        //{
        //    SqlConnection connection = new SqlConnection();
        //    SqlCommand command = new SqlCommand();
        //    modt = new DataTable("MoniData");

        //    connection.ConnectionString = dbconLocal;

        //    int retryCount = 10;

        //    using (SqlDataAdapter adapter = new SqlDataAdapter())
        //    {
        //        while (retryCount > 0)
        //        {
        //            try
        //            {

        //                command.Connection = connection;

        //                command.CommandText = "SELECT [FRMQRKANBAN], [REMARK3], [KBHROWID] FROM " + tableName + " where [FRMQRKANBAN] = '" + Kanban + "' and "+ " order by [CREATEDATE] desc, [CREATETIME] desc;";
        //                adapter.SelectCommand = command;


        //                adapter.Fill(modt);
        //                retryCount = 0;

        //            }//try end
        //            catch (Exception ex)
        //            {
        //                Console.WriteLine(ex.ToString());
        //                Thread.Sleep(600);
        //                retryCount--;

        //            }//catch end

        //        }//while end
        //        adapter.Dispose();

        //    }//using end DB
        //    return true;
        //}

        public static bool GetDataFromTBTT_KANBAN_HSelect(string dbconLocal, string tableName, ref DataTable modt, string selectFRMQRKANBAN)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {
                        string strTime = DateTime.Now.ToString("HHmmss");
                        command.Connection = connection;

                        if (Convert.ToInt32(strTime) <= 120000)
                        {
                            command.CommandText = "SELECT [FRMQRKANBAN], [KBHROWID]  FROM " + tableName + " where FRMQRKANBAN = '" + selectFRMQRKANBAN + "' and REMARK3 <> 'Cancel' and CREATEDATE = '" + DateTime.Now.ToString("yyyyMMdd") + "' and cast(CREATETIME as int) <= 120000 ;";

                        }
                        else
                        {
                            command.CommandText = "SELECT [FRMQRKANBAN], [KBHROWID]  FROM " + tableName + " where FRMQRKANBAN = '" + selectFRMQRKANBAN + "' and REMARK3 <> 'Cancel' and CREATEDATE = '" + DateTime.Now.ToString("yyyyMMdd") + "' and cast(CREATETIME as int) > 120000 ;";

                        }
                        //command.CommandText = "SELECT [FRMQRKANBAN]  FROM " + tableName + " where FRMQRKANBAN = '" + selectFRMQRKANBAN + "' and CREATEDATE = '" + DateTime.Now.ToString("yyyyMMdd") + "';";
                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBTT_KANBAN_HSelect_Temp(string dbconLocal, string tableName, ref DataTable modt, string selectFRMQRKANBAN)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {
                        string strTime = DateTime.Now.ToString("HHmmss");
                        command.Connection = connection;

                        //command.CommandText = "SELECT [FRMQRKANBAN], [KBHROWID]  FROM " + tableName 
                        //    + " where FRMQRKANBAN = '" + selectFRMQRKANBAN 
                        //    + "' and REMARK3 <> 'Cancel' and REMARK3 <> 'Finish' and CREATEDATE = '" 
                        //    + DateTime.Now.ToString("yyyyMMdd")
                        //    + "' and  (KBHROWID >= " +
                        //    "(SELECT MIN(KBHROWID) AS Expr1 FROM TT_KANBAN_H AS TT_KANBAN_H_1 WHERE FRMQRKANBAN = '" 
                        //    + selectFRMQRKANBAN + "' and ((REMARK3 = 'Printed') or (REMARK3 = 'Packing')) )) ;";


                        command.CommandText = "SELECT [FRMQRKANBAN], [KBHROWID]  FROM " + tableName
                            + " where FRMQRKANBAN = '" + selectFRMQRKANBAN
                            + "' and REMARK3 <> 'Cancel' and REMARK3 <> 'Finish' and CREATEDATE >= '"
                            + "20230727"
                            + "' and  (KBHROWID >= " +
                            "(SELECT MIN(KBHROWID) AS Expr1 FROM TT_KANBAN_H AS TT_KANBAN_H_1 WHERE FRMQRKANBAN = '"
                            + selectFRMQRKANBAN + "' and ((REMARK3 = 'Printed') or (REMARK3 = 'Packing')) )) ;";


                        //if (Convert.ToInt32(strTime) <= 120000)
                        //{
                        //    command.CommandText = "SELECT [FRMQRKANBAN], [KBHROWID]  FROM " + tableName + " where FRMQRKANBAN = '" + selectFRMQRKANBAN + "' and REMARK3 <> 'Cancel' and CREATEDATE = '" + DateTime.Now.ToString("yyyyMMdd") + "' and cast(CREATETIME as int) <= 120000 ;";

                        //}
                        //else
                        //{
                        //    command.CommandText = "SELECT [FRMQRKANBAN], [KBHROWID]  FROM " + tableName + " where FRMQRKANBAN = '" + selectFRMQRKANBAN + "' and REMARK3 <> 'Cancel' and CREATEDATE = '" + DateTime.Now.ToString("yyyyMMdd") + "' and cast(CREATETIME as int) > 120000 ;";

                        //}
                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBTT_KANBAN_HSelect_TempH(string dbconLocal, string tableName, ref DataTable modt, string selectFRMQRKANBAN)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {
                        string strTime = DateTime.Now.ToString("HHmmss");
                        command.Connection = connection;

                        command.CommandText = "SELECT [FRMQRKANBAN], [KBHROWID]  FROM " + tableName + " where FRMQRKANBAN = '" + selectFRMQRKANBAN + "' and (REMARK3 = 'PrintedH' or REMARK3 = 'PackingH') and CREATEDATE = '" + DateTime.Now.ToString("yyyyMMdd")
                            + "' ;";


                        //command.CommandText = "SELECT [FRMQRKANBAN], [KBHROWID]  FROM " + tableName + " where FRMQRKANBAN = '" + selectFRMQRKANBAN + "' and (REMARK3 = 'Packing' or REMARK3 = 'Printed') and CREATEDATE >= '" + "20230727"
                        //+ "' ;";


                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBTT_KANBAN_HSelect_Finish_Half(string dbconLocal, string tableName, ref DataTable modt, string selectFRMQRKANBAN)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {
                        string strTime = DateTime.Now.ToString("HHmmss");
                        command.Connection = connection;

                        if (Convert.ToInt32(strTime) <= 120000)
                        {
                            command.CommandText = "SELECT [FRMQRKANBAN], [KBHROWID]  FROM " + tableName + " where FRMQRKANBAN = '" + selectFRMQRKANBAN + "' and REMARK3 <> 'Cancel' and CREATEDATE = '" + DateTime.Now.ToString("yyyyMMdd") + "' and cast(CREATETIME as int) <= 120000 and [REMARK3] = 'Finish';";

                        }
                        else
                        {
                            command.CommandText = "SELECT [FRMQRKANBAN], [KBHROWID]  FROM " + tableName + " where FRMQRKANBAN = '" + selectFRMQRKANBAN + "' and REMARK3 <> 'Cancel' and CREATEDATE = '" + DateTime.Now.ToString("yyyyMMdd") + "' and cast(CREATETIME as int) > 120000 and [REMARK3] = 'Finish';";

                        }
                        //command.CommandText = "SELECT [FRMQRKANBAN]  FROM " + tableName + " where FRMQRKANBAN = '" + selectFRMQRKANBAN + "' and CREATEDATE = '" + DateTime.Now.ToString("yyyyMMdd") + "';";
                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBTT_KANBAN_HSelectHold(string dbconLocal, string tableName, ref DataTable modt, string selectFRMQRKANBAN)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {
                        string strTime = DateTime.Now.ToString("HHmmss");
                        command.Connection = connection;

                        command.CommandText = "SELECT [FRMQRKANBAN], [KBHROWID], [REMARK3]  FROM " + tableName + " where FRMQRKANBAN = N'" + selectFRMQRKANBAN + "' and (REMARK3 = N'HoldPacking' or REMARK3 = N'HoldPrinted');";


                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBTT_KANBAN_HSelect_Cancel(string dbconLocal, string tableName, ref DataTable modt, string selectFRMQRKANBAN, string strCreateDate)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {
                        string strTime = DateTime.Now.ToString("HHmmss");
                        command.Connection = connection;

                        //if (Convert.ToInt32(strTime) <= 120000)
                        //{
                        //command.CommandText = "SELECT [FRMQRKANBAN], [KBHROWID]  FROM " + tableName + " where FRMQRKANBAN = '" + selectFRMQRKANBAN + "' and REMARK3 <> 'Cancel' and CREATEDATE = '" + DateTime.Now.ToString("yyyyMMdd") + "' and cast(CREATETIME as int) <= 120000 ;";
                        
                        
                        //command.CommandText = "SELECT [FRMQRKANBAN], [KBHROWID], [REMARK3]  FROM " + tableName
                        //    + " where FRMQRKANBAN = '" + selectFRMQRKANBAN
                        //    + "' and REMARK3 <> 'Cancel' and  CREATEDATE = '" + strCreateDate + "'"

                            command.CommandText = "SELECT [FRMQRKANBAN], [KBHROWID], [REMARK3]  FROM " + tableName
                            + " where FRMQRKANBAN = '" + selectFRMQRKANBAN
                            + "' and REMARK3 <> 'Cancel' and  CREATEDATE >= '20230727'"


                            //+ " and [KBHROWID] > (select TOP(1) [KBHROWID] FROM " + tableName 
                            //+ " WHERE [REMARK3] = 'Finish' AND [FRMQRKANBAN] =  '" + selectFRMQRKANBAN +"')"
                            + " ; ";

                        //}
                        //else
                        //{
                        //command.CommandText = "SELECT [FRMQRKANBAN], [KBHROWID]  FROM " + tableName + " where FRMQRKANBAN = '" + selectFRMQRKANBAN + "' and REMARK3 <> 'Cancel' and CREATEDATE = '" + DateTime.Now.ToString("yyyyMMdd") + "' and cast(CREATETIME as int) > 120000 ;";
                        //    command.CommandText = "SELECT [FRMQRKANBAN], [KBHROWID]  FROM " + tableName + " where FRMQRKANBAN = '" + selectFRMQRKANBAN + "' and REMARK3 <> 'Cancel' and  ;";

                        //}
                        //command.CommandText = "SELECT [FRMQRKANBAN]  FROM " + tableName + " where FRMQRKANBAN = '" + selectFRMQRKANBAN + "' and CREATEDATE = '" + DateTime.Now.ToString("yyyyMMdd") + "';";
                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }


        public static bool GetDataFromTBTT_KANBAN_HSelect_Packing(string dbconLocal, string tableName, ref DataTable modt, string selectFRMQRKANBAN)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {
                        string strTime = DateTime.Now.ToString("HHmmss");
                        command.Connection = connection;

                        //if (Convert.ToInt32(strTime) <= 120000)
                        //{
                        //command.CommandText = "SELECT [FRMQRKANBAN], [KBHROWID]  FROM " + tableName + " where FRMQRKANBAN = '" + selectFRMQRKANBAN + "' and REMARK3 <> 'Cancel' and CREATEDATE = '" + DateTime.Now.ToString("yyyyMMdd") + "' and cast(CREATETIME as int) <= 120000 ;";
                        command.CommandText = "SELECT TOP (1) [FRMQRKANBAN], [KBHROWID], [REMARK3]  FROM " + tableName + " where FRMQRKANBAN = '" + selectFRMQRKANBAN + "' Order by [KBHROWID] desc  ; ";

                        //}
                        //else
                        //{
                        //command.CommandText = "SELECT [FRMQRKANBAN], [KBHROWID]  FROM " + tableName + " where FRMQRKANBAN = '" + selectFRMQRKANBAN + "' and REMARK3 <> 'Cancel' and CREATEDATE = '" + DateTime.Now.ToString("yyyyMMdd") + "' and cast(CREATETIME as int) > 120000 ;";
                        //    command.CommandText = "SELECT [FRMQRKANBAN], [KBHROWID]  FROM " + tableName + " where FRMQRKANBAN = '" + selectFRMQRKANBAN + "' and REMARK3 <> 'Cancel' and  ;";

                        //}
                        //command.CommandText = "SELECT [FRMQRKANBAN]  FROM " + tableName + " where FRMQRKANBAN = '" + selectFRMQRKANBAN + "' and CREATEDATE = '" + DateTime.Now.ToString("yyyyMMdd") + "';";
                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }


        public static bool GetDataFromTBTT_KANBAN_LSelect(string dbconLocal, string tableName, ref DataTable modt, string selectQRScan)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;

                        command.CommandText = "SELECT [QRSERIAL]  FROM " + tableName + " where QRSERIAL = '" + selectQRScan + "' and REMARK3 <> 'Cancel' and REMARK3 <> 'Delete';";
                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBTT_KANBAN_L_ID(string dbconLocal, string tableName, ref DataTable modt, string strID)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;

                        command.CommandText = "SELECT [QRSERIAL], [DRYTIME], [EXPIREDATE]  FROM " + tableName + " where KBHROWID = '" + strID + "' and REMARK3 <> 'Cancel' and REMARK3 <> 'Delete' order by KBLROWID asc;";
                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBSelectMaxID(string dbconLocal, string tableName, ref DataTable modt)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;

                        command.CommandText = "SELECT Max(ROWID) FROM " + tableName + " ;";

                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBSelectTT_KANBAN_HMaxID(string dbconLocal, string tableName, ref DataTable modt)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;

                        command.CommandText = "SELECT Max(KBHROWID) FROM " + tableName + " where REMARK3 = 'Packing' or REMARK3 = 'Printed';";

                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

        public static bool GetDataFromTBSelectUser(string dbconLocal, string tableName, ref DataTable modt, string userID)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand command = new SqlCommand();
            modt = new DataTable("MoniData");

            connection.ConnectionString = dbconLocal;

            int retryCount = 10;

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                while (retryCount > 0)
                {
                    try
                    {

                        command.Connection = connection;

                        command.CommandText = "SELECT USERID FROM " + tableName + " where USERID = '" + userID + "'; ";

                        adapter.SelectCommand = command;


                        adapter.Fill(modt);
                        retryCount = 0;

                    }//try end
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Thread.Sleep(600);
                        retryCount--;

                    }//catch end

                }//while end
                adapter.Dispose();

            }//using end DB
            return true;
        }

    }
}
