﻿using System;
using System.Globalization;
using System.Threading;
using System.IO;
// using System.Windows.Forms;
// openwebsite.exe
// ทำงานแบบ Windows Application 
namespace Original
{
    static class Program
    {
        public static string MyProg = "openwebsite".ToLower();	
        public static bool App4Console = false ; // true ทำงานแบบ Console Application ,fause ทำงานแบบ Windows Application 
        private static string MyApp = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;        
        public static string MyFolderApp = System.IO.Directory.GetCurrentDirectory();  // โพลเดอร์ทำงาน
        public static int nForWork = 1,nTemp=0;
        public static string cText = "", cTemp = "", cTemp2 = "";  // ตัวแปรดัมมี่
        public static bool insource=false ;
        public static bool inharddisk = false;
        public static string cFleWorkAct = "";  // ไว้ในในอนาคต ต่อไป 
        private static string cFle4Error = "_error.txt";
        private static bool ltemp = true; 

        // ตัวแปรเพิ่มเติ่ม
        // private static int var
        static void Information()
        {
            Util.Program.Pok_Mess("Adjust Pc's Environment" + Environment.NewLine+"For Complete");
        }

        static void Readme()
        {
            string Fle4Readme=MyFolderApp+"\\Readme.txt"; 
            TextWriter Logtxt = new StreamWriter(Fle4Readme);
            // การใช้งาน
            Logtxt.WriteLine("*" + MyProg + ".exe  ,DT : "+ File.GetLastWriteTime(MyApp).ToString("dd/MM/yy HH:mm"));
            Logtxt.WriteLine(MyApp);
            Logtxt.WriteLine(""); 
            Logtxt.WriteLine("ชุดคำสั่ง ");
            Logtxt.WriteLine("-" + MyProg + " " + " E --> ค้นหาด้วย Google ไปเรื่อยๆ");
            Logtxt.WriteLine("-" + MyProg + " " + " E --> ค้นหาด้วย Google");
            Logtxt.WriteLine("-" + MyProg + " " + " 1 --> ค้นหาด้วย Google +buddysoftware.net");
            Logtxt.WriteLine("-" + MyProg + " " + " 2 --> ค้นหาด้วย Google +youyod.com");
            Logtxt.WriteLine("-" + MyProg + " " + " 3 --> ค้นหาด้วย Google +uyod.net");
            Logtxt.WriteLine("-" + MyProg + " " + "-1 --> ค้นหาด้วย Google buddysoftware.net+");
            Logtxt.WriteLine("-" + MyProg + " " + "-2 --> ค้นหาด้วย Google youyod.com+");
            Logtxt.WriteLine("-" + MyProg + " " + "-3 --> ค้นหาด้วย Google uyod.net+");
            Logtxt.WriteLine(""); Logtxt.WriteLine("");	

            string[] readText;
            cTemp =  "xxxx.txt";
            if (File.Exists(cTemp)) {
                Logtxt.WriteLine("xxxx.txt ,DT:"+ File.GetLastWriteTime(cTemp).ToString("dd/MM/yy HH:mm"));
                Logtxt.WriteLine(cTemp);
                readText = File.ReadAllLines(cTemp);
                foreach (string s in readText) { if (s != "") { Logtxt.WriteLine(s.Trim()); } }
                Logtxt.WriteLine(""); Logtxt.WriteLine("");
            }
            Logtxt.Close();Logtxt.Dispose();
            if (Layout.Program.Password.Input_Password("Open Readme.txt","")) 
            { Util.Program.OpenWebSite(Fle4Readme);}
        }

        static void initProg() // เริ่มต้นทำงาน
        { }


        static void GoogleSearch2() // ค้นหาด้วย Google Search แบบต่อเนื่อง
        {
            Layout.Program.LayOut.BackGroud(3);
            // string cOption = "buddysoftware.net";
            int nCount = 0;
            int maxCount = 8;
            while (ltemp)
            {
                nCount++;
                switch (nCount) // Pipop
                {
                    case (1): cTemp = "โปรแกรมโรงแรมม่านรูด"; break;
                    case (2): cTemp = "โปรแกรมอพาร์ทเม้นท์"; break;
                    case (3): cTemp = "โปรแกรมโรงแรม"; break;
                    case (4): cTemp = "โปรแกรมPOS"; break;
                    case (5): cTemp = "โปรแกรมร้านอาหาร"; break;
                    case (6): cTemp = "โปรแกรมระบบเพ็ทแคร์"; break;
                    case (7): cTemp = "โปรแกรมระบบนวดสปา"; break;
                    case (8): cTemp = "โปรแกรมโรงแรมม่านรูด+โปรแกรมอพาร์ทเม้นท์+โปรแกรมโรงแรม+โปรแกรมPOS+โปรแกรมร้านอาหาร+โปรแกรมระบบเพ็ทแคร์+โปรแกรมระบบนวดสปา"; break;
                }
                Util.Program.SeleWebSite(0, "https://www.google.com/search?q=" + cTemp + "+buddysoftware.net");
                if (insource) { nTemp= 10; } else { nTemp= 600; }
                MyTime.Program.Pok_TimeWait(1, nTemp);
                string mref = "";
                if (!Layout.Program.myYesno.Form_Yesno("", cTemp + " หาต่อ",ref mref )) { ltemp = false; }
                if (nCount >= maxCount) { nCount = 0; }
            }
            cTemp = ""; cTemp2 = "";
        }


        static void GoogleSearch(int nOption) //ค้นหาด้วย Google Search 
        {
            Layout.Program.LayOut.BackGroud(3);
            string cOption="";
            switch (nOption)
            {
            case (0): cOption = ""; break;
            case (-1): case (1): cOption = "buddysoftware.net"; break;
            case (-2): case (2): cOption = "youyod.com";  break;
            case (-3): case (3): cOption = "uyod.net"; break;
            }
            for (int nSoft = 1; nSoft <= 3; nSoft++) 
            { 
                for (int nCount = 1; nCount <= 8; nCount++)  
                {
                    switch (nCount)
                    {
                        case (1): cTemp = "โปรแกรมโรงแรมม่านรูด"; break;
                        case (2): cTemp = "โปรแกรมอพาร์ทเม้นท์"; break;
                        case (3): cTemp = "โปรแกรมโรงแรม"; break;
                        case (4): cTemp = "โปรแกรมPOS"; break;
                        case (5): cTemp = "โปรแกรมร้านอาหาร"; break;
                        case (6): cTemp = "โปรแกรมระบบเพ็ทแคร์"; break;
                        case (7): cTemp = "โปรแกรมระบบนวดสปา"; break;
                        case (8): cTemp = "โปรแกรมโรงแรมม่านรูด+โปรแกรมอพาร์ทเม้นท์+โปรแกรมโรงแรม+โปรแกรมPOS+โปรแกรมร้านอาหาร+โปรแกรมระบบเพ็ทแคร์+โปรแกรมระบบนวดสปา"; break;
                    }
                    if (cOption!="")  {  if (nOption < 0) { cTemp = cOption +"+"+cTemp; } else { cTemp = cTemp + "+" + cOption; }  }
                    Util.Program.SeleWebSite(0, "https://www.google.com/search?q=" + cTemp );
                    if (nCount == 1) { MyTime.Program.Pok_TimeWait(1, 300); } else { MyTime.Program.Pok_TimeWait(1, 180); }
                    cTemp = "";
                }
            }
            Layout.Program.LayOut.ScreenShow(0, "เปิด Brower", "ค้นหาตาม ", cOption, "เสร็จแล้ว", "");
            cTemp = ""; cTemp2 = "";
        }


        static void Test_Prog()
        {
            Util.Program.SeleWebSite(0, "uyod.net");
        }



        static void Main(string[] args)
        {
	        initProg(); // เริ่มต้นทำงาน            
	        string cpFlag;
            if (MyApp.Substring(0,2)=="V:") { insource = true; } // Run กับ Source
            if (Directory.Exists("R:\\Temp")) {inharddisk=true;}  // Run กับ Harddisk   
            if (args.Length == 0) { if (insource) { cpFlag = "T"; } else { cpFlag = "1"; } }  // Pipop T เป็นการทดสอบ
            else { cpFlag = args[0].Trim(); }
            nForWork=1;  //    PipopYou ปรกติ  1 nForWork=0 ไม่ทำอะไรเลย ,1 ทำงานตามปรกติ 2 ไม่Runโปรแกรมและมีเตือน  
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); // เปลี่ยนรูปแบบวันที่ เป็น GB
            switch (cpFlag) // Switch
            {
                case ("0"): 
                case ("?"): Readme(); break;
                case ("T"): Test_Prog();    break;
                case ("E"): GoogleSearch(0); break; // ช่องว่าง
                case ("1"):  GoogleSearch(1);  break; // buddysoftware.net
                case ("2"): GoogleSearch(2); break; // youyod.com
                case ("3"): GoogleSearch(3); break; // uyod.net
                case ("4"): GoogleSearch(-1); break; // buddysoftware.net
                case ("5"): GoogleSearch(-2); break; // youyod.com
                case ("6"): GoogleSearch(-3); break; // uyod.net
                case ("C"): GoogleSearch2(); break; // ทำงานยาว
                default:  break;  
            } 
        }
    }
}

