Пример #1
0
        static void Main(string[] args)
        {
            // Run each one independently

            /*
             * A_ThreadTypes.Run();
             * B_ThreadCreation.Run();
             * C_ThreadPool.Run();
             * FibonacciRun.Run();
             * D_ExceptionHandling.Run();
             * E_ThreadPriority.Run();
             * F_ThreadSynchronizationAndBlocking.Run();
             * G_ThreadLocking.Run();
             * H_ThreadMonitoring.Run();
             * I_PausingAndResuming.Run();
             * J_Deadlock.Run();
             * K_Mutex.Run();
             * L_SynchronizationContext.Run();
             * M_ConcurrentDictionary.Run();
             * N_ThreadJoin.Run();
             *
             */

            P_AutoResetEvent.Run();

            PrintUtility.PrintSubTitle("MAIN THREAD EXITING \nBackground Threads still running after main thread has finished because a Foreground Thread is still alive");
            Console.ReadLine();
        }
Пример #2
0
 public static void Run()
 {
     PrintUtility.PrintTitle("FOREGROUND & BACKGROUND THREADS");
     PrintUtility.PrintSubTitle("Background Thread will still run after main thread has finished because a Foreground Thread is still alive");
     RunForegroundThread();
     RunBackgroundThread();
 }
Пример #3
0
        public static void Run()
        {
            PrintUtility.PrintTitle("PYRAMIDS EXAMPLE");

            int numberOfRows = 9, rowCount = 1;

            // We start in reverse order to facilitate more preceding spaces at top of pyramid (N-1 for each iteration = 17 >> 0)
            for (int i = numberOfRows; i > 0; i--)
            {
                // Print Preceding Spaces
                for (int j = 1; j < i * 2; j++) // Double up (i*2)
                {
                    Console.Write(" ");
                }

                // Print Numbers Ascending (from 1 to rowCount)
                for (int k = 1; k <= rowCount; k++)
                {
                    Console.Write(k + " ");
                }

                // Print Numbers Descending (from rowCount-1 to 1)
                for (int l = rowCount - 1; l >= 1; l--)
                {
                    Console.Write(l + " ");
                }

                // Start a new Line
                Console.WriteLine();

                // Increment row count
                rowCount++;
            }
        }
Пример #4
0
        public static void Run()
        {
            PrintUtility.PrintTitle("AUTO RESET EVENT EXAMPLE");

            PrintUtility.PrintSubTitle("Press Enter to Start 3 named threads and start them");
            Console.ReadLine();

            for (int i = 0; i < 3; i++)
            {
                Thread t = new Thread(ThreadProc);
                t.Name = $"Thread{i}";
                t.Start();
            }
            Thread.Sleep(250);

            for (int i = 0; i < 2; i++)
            {
                Console.WriteLine("Press Enter to release another thread.");
                Console.ReadLine();
                event_1.Set();
                Thread.Sleep(250);
            }


            PrintUtility.PrintSubTitle("All threads are now waiting on AutoResetEvent #2.");
            for (int i = 0; i < 3; i++)
            {
                Console.WriteLine("Press Enter to release a thread.");
                Console.ReadLine();
                event_2.Set();
                Thread.Sleep(250);
            }
        }
        public static void Run()
        {
            PrintUtility.PrintTitle("BINARY OVERLOADING");

            // Create two 'Point' objects.
            Point p1 = new Point(100, 100);
            Point p2 = new Point(40, 40);

            Console.WriteLine("p1 = {0}", p1);
            Console.WriteLine("p2 = {0}", p2);

            // Add the points to make a bigger point
            Console.WriteLine($"p1 + p2: {p1 + p2}");

            // Subtract the points to make a smaller point
            Console.WriteLine($"p1 - p2: {p1 + p2}");


            // += and –+ Operators (FREEBIES)
            PrintUtility.PrintSubTitle("+= and –+ Operators");

            // +=
            Point p3 = new Point(90, 5);

            Console.WriteLine($"p3 = {p3}");
            Console.WriteLine($"p3 += p2: {p3 += p2}");

            // -=
            Point p4 = new Point(0, 500);

            Console.WriteLine($"p4 = {p4}");
            Console.WriteLine($"p4 -= p3: {p4 -= p3}");
        }
Пример #6
0
 static void Main(string[] args)
 {
     List <string> mylist1       = new List <string>(new string[] { });
     PrintUtility  printutilitya = new PrintUtility();
     bool          read          = printutilitya.ReadToFile(mylist1);
     bool          write         = printutilitya.WriteToFile(mylist1);
 }
Пример #7
0
        protected override void ExecPrint()
        {
            #region 执行打印
            try
            {
                this.Cursor = Cursors.WaitCursor;

                GPrinter gPrter = new GPrinter();
                gPrter.DocumentName        = "存货档案";
                gPrter.CustomPrintSettings = this.m_strPrintSettings;

                Title title = new Title();
                title.Text   = "存货档案";
                gPrter.Title = title;

                gPrter.MultiHeader = PrintUtility.DataGridHeader1(this.dgM);
                gPrter.Body        = PrintUtility.DataGridBody1(this.dgM, 25, null, null);

                Print.Run1(gPrter);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
            #endregion
        }
Пример #8
0
 private static void TestSleep()
 {
     PrintUtility.PrintSubTitle("THREAD SLEEP");
     Console.WriteLine($"Thread Sleep started time: {DateTime.Now}");
     Thread.Sleep(2000);
     Console.WriteLine($"Thread Sleep ended time: {DateTime.Now}");
 }
Пример #9
0
 public static void Run()
 {
     PrintUtility.PrintTitle("THREAD SYNCHRONIZATION AND BLOCKING");
     TestSleep();
     TestJoin();
     TestTaskWait();
 }
Пример #10
0
        public static void Run()
        {
            PrintUtility.PrintTitle("PYRAMIDS EXAMPLE");

            int numberOfRows = 9, rowCount = 1;

            // We start in reverse order to facilitate more preceding spaces at top of pyramid (N-1 for each iteration = 8, 7, 6, 5, 4, 3, 2, 1)
            for (int i = numberOfRows; i > 0; i--)
            {
                // Print Preceding Spaces
                for (int j = 0; j < i; j++)
                {
                    Console.Write(" ");
                }

                // Print numbers (from 1 to rowCount)
                for (int k = 1; k <= rowCount; k++)
                {
                    Console.Write("* ");
                }

                // Start a new Line
                Console.WriteLine();

                // Increment row count
                rowCount++;
            }
        }
        public void SetText(string sText, Enumerations.FontSize oFontSize = Enumerations.FontSize.Medium, FontStyle oFontStyle = FontStyle.Regular, bool bFontExpanded = false, Enumerations.TextAlignmentType oTextAlignmentType = Enumerations.TextAlignmentType.Center, bool bBreakLine = true)
        {
            string sSpaces;

            switch (oTextAlignmentType)
            {
            case Enumerations.TextAlignmentType.Center:
                sSpaces = PrintUtility.GetCenterAlignmentText(sText, TotalCharactersPerLine, oFontSize);
                SetText(sSpaces, oFontSize, FontStyle.Regular, bFontExpanded, Enumerations.TextAlignmentType.Left, false);
                break;

            case Enumerations.TextAlignmentType.Right:
                sSpaces = PrintUtility.GetRightAlignmentText(sText, TotalCharactersPerLine, oFontSize);
                SetText(sSpaces, oFontSize, FontStyle.Regular, bFontExpanded, Enumerations.TextAlignmentType.Left, false);
                break;

            case Enumerations.TextAlignmentType.Left:
            default:
                break;
            }

            int iItalic    = oFontStyle.ToString().Contains(FontStyle.Italic.ToString()) ? 1 : 0;
            int iUnderline = oFontStyle.ToString().Contains(FontStyle.Underline.ToString()) ? 1 : 0;
            int iExpanded  = bFontExpanded ? 1 : 0;
            int iBold      = oFontStyle.ToString().Contains(FontStyle.Bold.ToString()) ? 1 : 0;

            Commands.Add(new Command("BematechInterface.FormataTX", () => BematechInterface.FormataTX(sText, (int)oFontSize, iItalic, iUnderline, iExpanded, iBold)));

            if (bBreakLine)
            {
                BreakLine(1);
            }
        }
Пример #12
0
        private static void SearchSortedlist(List <string> list, string searchValue)
        {
            // Again iterate from start to finish and break out of the loop if we find the value we're looking for.
            // However, because the list is sorted, we can compare our values and if the current value is greater than the search value,
            // we can then safely assume that the search value is not in the list, and break out of the loop without having to traverse to the end.

            list.Sort(); // SORT THE LIST

            int  searchesPerformed = 0;
            bool found             = false;

            for (int i = 0; i < list.Count; i++)
            {
                ++searchesPerformed;
                if (list[i].CompareTo(searchValue) > 0)  // case sensitive compare
                {
                    // If current value is greater than the search value, then we know that our search value is not in the list.
                    break;
                }
                else if (list[i].CompareTo(searchValue) == 0) // case sensitive compare
                {
                    // Found It !
                    found = true;
                    break;
                }
            }
            PrintUtility.PrintSubTitle(found ? $"{searchesPerformed} SEARCHES PERFORMED TO FIND '{searchValue}' (SORTED LIST)" : $"{searchesPerformed} SEARCHES PERFORMED: '{searchValue}' COULD NOT BE FOUND (SORTED LIST)");
        }
Пример #13
0
        void printDoc_PrintPage(object sender, PrintPageEventArgs ev)
        {
            List <TicketExceptions> items = lvVoidCancelled.Items.Cast <TicketExceptions>().ToList <TicketExceptions>();
            PrintUtility            util  = new PrintUtility(items);

            util.GetCommonPrintValues(ev);
        }
 protected override void CreatePaginator(DrawingVisual visual, Size printSize)
 {
     if (PrintUtility != null)
     {
         Paginator = new DataGridPaginator(visual, printSize, PrintUtility.GetPageMargin(CurrentPrinterName), PrintTableDefination);
     }
 }
        private static void find(string str)
        {
            PrintUtility.PrintSubTitle($"FINDING DUPLICATES LETTERS IN {str}");

            Dictionary <char, int> characterCount = new Dictionary <char, int>(); // Collection to hold each letter and it's count

            char[] characters = str.ToCharArray();                                // Throw all characters into a char array

            foreach (char c in characters)                                        // Iterate through the array and tally each character
            {
                if (characterCount.ContainsKey(c))                                // Character already exists in the list
                {
                    characterCount[c] += 1;                                       // Increment count
                }
                else
                {
                    characterCount.Add(c, 1);                                   // Add new character to list
                }
            }

            foreach (var pair in characterCount)                                 // Iterate through result set and print those with a value greater than 1.
            {
                if (pair.Key != ' ' && pair.Value > 1)
                {
                    Console.WriteLine($"{pair.Key}: {pair.Value}");
                }
            }
        }
 public static void Run()
 {
     PrintUtility.PrintTitle("FIND DUPLICATE LETTERS");
     find("Better Be Butter");
     find("Fresh Fish");
     find("Fruity Wuity");
 }
 public static void Run()
 {
     PrintUtility.PrintTitle("EXCEPTION HANDLING");
     Example2();
     Example3();
     //Example1(); Commented out because it throws an unhandled error, feel free to uncomment.
 }
        public void SetText(string text, int FontSize = 10, FontStyle fontStyle = FontStyle.Regular, int LineHeight = 60, Enumerations.TextAlignmentType textAlignmentType = Enumerations.TextAlignmentType.Center)
        {
            switch (textAlignmentType)
            {
            case Enumerations.TextAlignmentType.Center:
                text = PrintUtility.GetCenterAlignmentText(text, TotalCharactersPerLine);
                break;

            case Enumerations.TextAlignmentType.Right:
                text = PrintUtility.GetRightAlignmentText(text, TotalCharactersPerLine);
                break;

            case Enumerations.TextAlignmentType.Left:
            default:
                break;
            }

            int italic    = fontStyle.ToString().Contains(FontStyle.Italic.ToString()) ? 1 : 0;
            int underline = fontStyle.ToString().Contains(FontStyle.Underline.ToString()) ? 1 : 0;
            int bold      = fontStyle.ToString().Contains(FontStyle.Bold.ToString()) ? 1 : 0;

            Commands.Add(new Command("BematechInterface.FormataTX", () => BematechInterface.FormataTX(text, 2, italic, underline, 0, bold)));

            BreakLine(1);
        }
Пример #19
0
 public static void Run()
 {
     PrintUtility.PrintTitle("THREAD POOLS");
     PrintUtility.PrintSubTitle("POOLED THREADS ARE ALWAYS BACKGROUND THREADS");
     QueueUserWorkItemMethod("Hello");
     AsynchronousDelegatesMethod();
 }
Пример #20
0
        private static void RunExample3()
        {
            PrintUtility.PrintSubTitle("Example 3");
            MutexExample2 ex = new MutexExample2();

            ex.Run();
        }
        public static void Run()
        {
            // Demonstrates how to use indexer methods using an numeric index value.
            // See Also: PersonCollection class under 'Models' folder. Here you will notice the 'this' keyword used to facilitate this functionality.

            PrintUtility.PrintTitle("NUMERIC VALUE INDEXER METHOD EXAMPLE");

            PersonCollection myPeople = new PersonCollection();

            // Add objects with indexer syntax.
            myPeople[0] = new Person("Homer", "Simpson", 40);
            myPeople[1] = new Person("Marge", "Simpson", 38);
            myPeople[2] = new Person("Lisa", "Simpson", 9);
            myPeople[3] = new Person("Bart", "Simpson", 7);
            myPeople[4] = new Person("Maggie", "Simpson", 2);

            // Now obtain and display each item using indexer.
            for (int i = 0; i < myPeople.Count; i++)
            {
                Console.WriteLine($"Person number: {i}");
                Console.WriteLine($"Name: {myPeople[i].FirstName} {myPeople[i].LastName}");
                Console.WriteLine($"Age: {myPeople[i].Age}");
                Console.WriteLine();
            }
        }
Пример #22
0
        private static void check2(int originalNumber)
        {
            int copyOfNumber = originalNumber;
            int exponent     = originalNumber.ToString().Length;
            int result       = 0;

            // Comments show the results for each iteration for the number 153
            while (copyOfNumber != 0)
            {
                int lastDigit = copyOfNumber % 10;                  // = 3, 5, 1
                int lastDigitToThePowerOfExponent = 1;              // = 1

                for (int i = 0; i < exponent; i++)
                {                                                                              // 1st iteration {3} = (1 * 3), (3 * 3), (9 * 3) = 27
                    lastDigitToThePowerOfExponent = lastDigitToThePowerOfExponent * lastDigit; // 2nd iteration {5} = (1 * 5), (5 * 5), (25 * 5) = 125
                }                                                                              // 3rd iteration {1} = (1 * 1), (1 * 1), (1 * 1) = 1

                result       = result + lastDigitToThePowerOfExponent;                         // = 27, 152, 153
                copyOfNumber = copyOfNumber / 10;                                              // = 15, 1, 0

                // uncomment the following line to see how it works
                //Console.WriteLine($"lastDigit: {lastDigit} - lastDigitToThePowerOfNoOfDigits: {lastDigitToThePowerOfNoOfDigits} - result: {result} - copyOfNumber: {copyOfNumber}");
            }

            PrintUtility.PrintSubTitle(result == originalNumber ? $"{originalNumber} IS AN ARMSTRONG NUMBER: RESULT = {result}" : $"{originalNumber} IS NOT AN ARMSTRONG NUMBER: RESULT = {result}");
        }
Пример #23
0
        public static void Run()
        {
            PrintUtility.PrintTitle("MEAN & STANDARD DEVIATION");

            // Generate some random numbers
            int[]  nums = new int[10000];
            Random r    = new Random();

            for (int i = 0; i < nums.Length; i++)
            {
                nums[i] = r.Next(10, 20);
            }

            // Get the mean
            double mean = nums.AsParallel().Average();


            double standardDeviation = nums.AsParallel().Aggregate(
                0.0,                                                       // initialize subtotal. Use decimal point to tell the compiler that this is a double type
                (subtotal, item) => subtotal + Math.Pow((item - mean), 2), // do this on each thread
                (total, thisThread) => total + thisThread,                 // aggregate results after all threads are done.
                (finalSum) => Math.Sqrt((finalSum / (nums.Length - 1)))    // perform standard deviation calc on the aggregated result.
                );

            Console.WriteLine($"Mean value is = {mean}");
            Console.WriteLine($"Standard deviation is {standardDeviation}");
        }
Пример #24
0
        public static void Run()
        {
            PrintUtility.PrintTitle("PYRAMIDS EXAMPLE");

            int numberOfRows = 9, rowCount = 1;

            // We start in order to facilitate less preceding spaces at top of pyramid (N+1 for each iteration = 0 >> 17)
            for (int i = 1; i <= numberOfRows; i++)
            {
                // Print Preceding Spaces
                for (int j = 0; j <= i * 2 - 2; j++)
                {
                    Console.Write(" ");
                }

                // Print Numbers Ascending
                for (int k = 1; k <= numberOfRows - rowCount + 1; k++)
                {
                    Console.Write(k + " ");
                }

                // Print Numbers Descending
                for (int l = numberOfRows - rowCount; l >= 1; l--)
                {
                    Console.Write(l + " ");
                }

                // Start a new Line
                Console.WriteLine();

                // Increment row count
                rowCount++;
            }
        }
Пример #25
0
        public override void FetchSetting()
        {
            base.FetchSetting();

            Scale     = PrintUtility.GetScale();
            FitToPage = PrintUtility.GetFitToPage();
        }
Пример #26
0
 public static void Run()
 {
     PrintUtility.PrintTitle("THREAD MONITORING");
     EnterAndExitExample();
     PoolExample();
     TickTockExample();
 }
Пример #27
0
        private static void BuiltInSearch(List <String> list, string searchValue)
        {
            // This returns the index of "cantaloupe".
            int i = list.BinarySearch(searchValue);

            PrintUtility.PrintSubTitle($"BUILT-IN SEARCH FACILITY - {searchValue} can be found at index {i}");
        }
Пример #28
0
        private static void PoolExample()
        {
            PrintUtility.PrintSubTitle("POOL EXAMPLE");
            Thread[] threads = new Thread[3];

            // Create thread pool
            for (int i = 0; i < 3; i++)
            {
                threads[i]              = new Thread(new ThreadStart(DoPoolWork));
                threads[i].Name         = $"t{i+1}";
                threads[i].IsBackground = true;
                threads[i].Start();
            }

            // Start each one
            for (int i = 0; i < 20; i++)
            {
                Console.WriteLine("Sleeping");
                Thread.Sleep(1000);
                Console.WriteLine("Awake");
                lock (locker2)
                {
                    Console.WriteLine(" Before Pulsing");
                    Monitor.Pulse(locker2);
                    Console.WriteLine("After Pulsing");
                }
            }
        }
Пример #29
0
        private static void CustomSearch(List <String> list, string searchValue)
        {
            PrintUtility.PrintSubTitle("HAND-BALL APPROACH - DIVIDE & CONQUER");
            int low = 0, high = list.Count - 1, mid = 0, idx = -1;

            while (low <= high)
            {
                mid = (low + high) / 2;                                                 // Divide the list

                Console.WriteLine($"Lower: {low}\t => Higher: {high}\t => Mid: {mid}"); // Print out index positions to show how it actually works.

                if (list[mid].CompareTo(searchValue) < 0)
                {
                    // If the value of the middle element in the list is lesser than the search value, we need to look to the right of the list.
                    // Therefore we set the lower boundary position to the middle + 1;
                    low = mid + 1;
                }
                else if (list[mid].CompareTo(searchValue) > 0)
                {
                    // If the value of the middle element in the list is greater than the search value, we need to look to the left of the list.
                    // Therefore we set the higher boundary position to the middle - 1;
                    high = mid - 1;
                }
                else
                {
                    // We've found it
                    idx = mid;
                    break;
                }
            }
            // Print the index of the 'searchValue' if found, otherwise notify that the search value is not in the list.
            PrintUtility.PrintSubTitle(idx >= 0 ? $"'HandBallSearch' - {searchValue} can be found at index {idx}" : $"'HandBallSearch' - {searchValue} could not be found");
        }
        private void LoadSerialConnPrinters()
        {
            var devices = PrintUtility.GetComDevicesInfo();

            devices.ForEach(item =>
            {
                var printerModel = SearchWithInString(item.Name);

                if (printerModel != null)
                {
                    var printer = new Printer
                    {
                        Manufacturer   = printerModel.Manufacturer,
                        Name           = printerModel.Name,
                        Model          = printerModel.Model,
                        IpAddress      = null,
                        ConnectionType = item.ComPort.ToEnum <Enumerations.ConnectionType>()
                    };

                    var displayText = string.Format("{0} ({1})", printer.Name, printer.ConnectionType);

                    cboPrinters.Items.Add(new KeyValuePair <string, Printer>(displayText, printer));

                    if (PrinterHandler != null)
                    {
                        var printerConfigText = string.Format("{0} ({1})", PrinterHandler.PrinterConfig.Name, PrinterHandler.PrinterConfig.ConnectionType);

                        if (displayText.Equals(printerConfigText))
                        {
                            cboPrinters.Text = displayText;
                        }
                    }
                }
            });
        }
Пример #31
0
        /// <summary>
        /// 执行逻辑
        /// </summary>
        /// <param name="executionContext"></param>
        /// <returns></returns>
        protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext)
        {
            IList<PrintItem> resultPrintItemList = new List<PrintItem>();
            Session session =CurrentSession;
            var printItemList = (IList<PrintItem>)session.GetValue(Session.SessionKeys.PrintItems);

            ILabelTypeRepository lblTypeRepository = RepositoryFactory.GetInstance().GetRepository<ILabelTypeRepository, LabelType>();
            PrintUtility resolvePrintTemplate = null;
            if (printItemList != null && printItemList.Count > 0)  //無LabelType時不做檢查及報錯
            {
                Nullable<bool> hasExceptStation = null; 
                for (int i = 0; i < printItemList.Count; i++)
                {
                    PrintItem tempPrintItem = printItemList[i];
                    #region decide template logical
                    if (tempPrintItem.PrintMode == Bat)
                    {
                        PrintTemplate newTemplate = lblTypeRepository.GetPrintTemplate(tempPrintItem.TemplateName);
                        if (newTemplate != null)
                        {
                            //if (IsReprint)
                            //{
                            //    tempPrintItem.Piece = 1;
                            //}
                            //else
                            //{
                            tempPrintItem.Piece = newTemplate.Piece;
                            //}
                            tempPrintItem.SpName = newTemplate.SpName;
                            resultPrintItemList.Add(tempPrintItem);
                        }
                        else if (NotExistException)
                        {
                            //var logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                            //FisException ex;
                            //List<string> erpara = new List<string>();
                            //erpara.Add(tempPrintItem.TemplateName);
                            //ex = new FisException("CHK064", erpara);
                            //logger.Error(ex.mErrmsg, ex);
                            //throw ex;
                            if (!hasExceptStation.HasValue)
                            {
                                hasExceptStation = checkExceptStation();
                            }
                            if (!hasExceptStation.Value)
                            {
                                throw new FisException("CHK064", new string[] { tempPrintItem.LabelType + "/" + tempPrintItem.TemplateName });
                            }
                        }
                       

                    }
                    else if (tempPrintItem.PrintMode == Template)
                    {
                        if (resolvePrintTemplate == null)
                        {
                            resolvePrintTemplate = new PrintUtility(session, ModelName(session), MONO(session), Dn(session), PartNo(session), Customer);
                        }
                        PrintTemplate newTemplate = resolvePrintTemplate.GetPrintTemplate(tempPrintItem.LabelType, tempPrintItem.RuleMode, tempPrintItem.PrintMode);
                        //PrintTemplate newTemplate = lblTypeRepository.GetPrintTemplate(tempPrintItem.LabelType, ModelName, MONO, Dn, PartNo, tempPrintItem.RuleMode,Customer);
                        if (newTemplate != null)
                        {
                            //if (IsReprint)
                            //{
                            //    tempPrintItem.Piece = 1;
                            //}
                            //else
                            //{
                            tempPrintItem.Piece = newTemplate.Piece;
                            //}
                            tempPrintItem.TemplateName = newTemplate.TemplateName;
                            tempPrintItem.Layout = newTemplate.Layout;
                            resultPrintItemList.Add(tempPrintItem);
                        }
                        else if (NotExistException)
                        {
                            //var logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                            //FisException ex;
                            //List<string> erpara = new List<string>();
                            //erpara.Add(tempPrintItem.LabelType);
                            //ex = new FisException("CHK065", erpara);
                            //logger.Error(ex.mErrmsg, ex);
                            //throw ex;
                            if (!hasExceptStation.HasValue)
                            {
                                hasExceptStation = checkExceptStation();
                            }

                            if (!hasExceptStation.Value)
                            {
                                throw new FisException("CHK065", new string[] { tempPrintItem.LabelType });
                            }
                        }                       

                    }
                    else if (tempPrintItem.PrintMode == Bartender ||
                              tempPrintItem.PrintMode == BartenderSrv)
                    {
                        //PrintTemplate newTemplate = lblTypeRepository.GetPrintTemplate(tempPrintItem.TemplateName);
                        if (resolvePrintTemplate == null)
                        {
                            resolvePrintTemplate = new PrintUtility(session, ModelName(session), MONO(session), Dn(session), PartNo(session), Customer);
                        }
                        PrintTemplate newTemplate = resolvePrintTemplate.GetPrintTemplate(tempPrintItem.LabelType, tempPrintItem.RuleMode, tempPrintItem.PrintMode);
                        if (newTemplate != null)
                        {
                            //if (IsReprint)
                            //{
                            //    tempPrintItem.Piece = 1;
                            //}
                            //else
                            //{
                            tempPrintItem.Piece = newTemplate.Piece;
                            //}
                            tempPrintItem.TemplateName = newTemplate.TemplateName;
                            tempPrintItem.SpName = newTemplate.SpName;
                            resultPrintItemList.Add(tempPrintItem);
                        }
                        else if (NotExistException)
                        {
                           // var logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                            //FisException ex;
                            //List<string> erpara = new List<string>();
                            //erpara.Add(tempPrintItem.TemplateName);
                            //ex = new FisException("CHK064", erpara);
                            ////logger.Error(ex.mErrmsg, ex);
                            //throw ex;
                            if (!hasExceptStation.HasValue)
                            {
                                hasExceptStation = checkExceptStation();
                            }

                            if (!hasExceptStation.Value)
                            {
                                throw new FisException("CHK065", new string[] { tempPrintItem.LabelType });
                            }
                        }
                    }
                    #endregion
                }

                if (resultPrintItemList.Count == 0 & !NotExistException)
                {
                    //var logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                    //FisException ex;
                    //List<string> erpara = new List<string>();
                    //ex = new FisException("CHK065",new string[]{""});
                    ////logger.Error(ex.mErrmsg, ex);
                    //throw ex;
                    if (!hasExceptStation.HasValue)
                    {
                        hasExceptStation = checkExceptStation();
                    }

                    if (!hasExceptStation.Value)
                    {
                        throw new FisException("CHK065", new string[] { string.Join(",", printItemList.Select(x => x.LabelType + "/" + x.TemplateName).ToArray()) });
                    }         
                }

                session.AddValue(Session.SessionKeys.PrintItems, resultPrintItemList);

                #region write print log
                if (this.IsWritePrintLog && resultPrintItemList != null && resultPrintItemList.Count > 0)
                {
                    ActivityCommonImpl utl = ActivityCommonImpl.Instance;
                    var rep = RepositoryFactory.GetInstance().GetRepository<IPrintLogRepository, PrintLog>();
                    var reprintRep = RepositoryFactory.GetInstance().GetRepository<IReprintLogRepository, ReprintLog>();
                    string descrMsg= "Line:{0} PrintMode:{1} SPName:{2} Pieces:{3}";
                    string reasonMsg = "Template:{0}";
                    string begNo = utl.GetPrintLogBegNoValue(session, this.PrintLogBegNo, this.SessionBegNoName);
                    string endNo = utl.GetPrintLogEndNoValue(session,this.SessionEndNoName);
                    begNo = begNo ?? session.Key;
                    endNo = endNo ?? session.Key;
                    foreach (PrintItem item in resultPrintItemList)
                    {
                        if (this.IsReprint)
                        {
                            var log = new ReprintLog
                            {
                                LabelName = item.LabelType,
                                BegNo = begNo,
                                EndNo =endNo,
                                Descr = string.Format(descrMsg,
                                                                    this.Line?? "",
                                                                    item.PrintMode.ToString(),
                                                                    item.SpName,
                                                                    item.Piece.ToString()),
                                Reason = session.GetValue(Session.SessionKeys.Reason) as string ,
                                Editor = this.Editor
                            };
                            if (string.IsNullOrEmpty(log.Reason))
                            {
                                log.Reason = string.Format(reasonMsg, item.TemplateName);
                            }
                            else
                            {
                                log.Reason = log.Reason +" "+ string.Format(reasonMsg, item.TemplateName);
                            }
                            reprintRep.Add(log, session.UnitOfWork);
                        }
                        else
                        {
                            var log = new PrintLog
                            {
                                LabelTemplate = item.TemplateName,
                                Station = this.Station,
                                Name = item.LabelType,
                                BeginNo = begNo,
                                EndNo = endNo,
                                Descr = string.Format(descrMsg,
                                                                    this.Line ?? "",
                                                                    item.PrintMode.ToString(),
                                                                    item.SpName,
                                                                    item.Piece.ToString()),
                                Editor = this.Editor
                            };

                            rep.Add(log, session.UnitOfWork);
                        }
                    }
                }
                #endregion
            }
            //Vincent disable code don't Change printitem object or not
            //else
            //{
            //   // var logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            //    FisException ex;
            //    List<string> erpara = new List<string>();
            //    ex = new FisException("CHK066", erpara);
            //   // logger.Error(ex.mErrmsg, ex);
            //    throw ex;
            //}
            return base.DoExecute(executionContext);
        }