1/31/2022

VB : VB Read Data To Array And Extract To Use Data. To Read Data Again

 

VB : VB Read Data To Array And Extract To Use Data. To Read Data Again
Example :
  1.  
  2.             Dim ArrayBarCode As ArrayList
  3.             ArrayBarCode = New ArrayList
  4.             .
  5.             .
  6.             .
  7.             While myReader.Read()
  8.                 FirstCode = myReader.Item("FirstCode").ToString()
  9.                 AccountCode = myReader.Item("AccountCode").ToString()
  10.                 TypeCode = myReader.Item("TypeCode").ToString()
  11.                 SubTypeCode = myReader.Item("SubTypeCode").ToString()
  12.                 RunNo = myReader.Item("RunNo").ToString()
  13.  
  14.                 If CheckBox_LastTransaction.Checked = True Then
  15.                     ArrayBarCode.Add(BarCode) '###### Add BarCode เข้า Array เพื่อไป Loop ออกรายงานอีกรอบ เพราะ Reader ซ่อน Loop ไม่ได้
  16.                 End If
  17.             End While
  18.             myReader.Close()
  19.             Dim m As Long
  20.             line = 5
  21.             If CheckBox_LastTransaction.Checked = True Then
  22.                 firstSheet.getCellByPosition(8, 4).String = "ประวัติการโอนย้ายครั้งล่าสุด"
  23.                 For m = 0 To ArrayBarCode.Count - 1
  24.                     '########## Select Data From Other Table Again #############'
  25.                     SQLTmp = "SELECT OldUser,Reason,EmpName FROM sci_ams.asset_move " _
  26.                     & " LEFT JOIN sci._employees ON _employees.EmpID= asset_move.OldUser " _
  27.                     & " WHERE BarCode = '" & ArrayBarCode(m) & "' AND End = 'Y' " _
  28.                     & " ORDER BY Id DESC"
  29.  
  30.                     myCommand.CommandText = SQLTmp
  31.                     myAdapter.SelectCommand = myCommand
  32.                     myReader = myCommand.ExecuteReader
  33.                     If (myReader.Read()) Then
  34.                         LastTransaction = myReader.Item("OldUser").ToString() & ":" & myReader.Item("EmpName").ToString() & " : " & myReader.Item("Reason").ToString()
  35.                     End If
  36.  
  37.                     line = line + 1
  38.                     myReader.Close() '###### ต้อง Close ไม่อย่างนั้น ERROR เพราะอยู่ใน Loop อ่านจาก DB หลายรอบ
  39.                 Next

End If

1/22/2022

Windows10 21H2 Add Printer ที่ Shared จากเครื่องอื่น ไม่ได้

Windows10 21H2 Add Printer ที่ Shared จากเครื่องอื่น ไม่ได้

How to Fix Windows Cannot Connect to Printer - Error 0x0000011b


วิธีแก้ไข เข้าไปที่
C:\Windows\regedit > HKEY LOCAL MACHINE > SYSTEM > CURRENTCONTROLSET > CONTROL > PRINT
คลิ้กที่ Print ใน Regedit แล้วคลิ้กขวา > New > DWORD (32-BIT)VALUE เปลี่ยนชื่อเป็น RpcAuthnLevelPrivacyEnabled แล้วก็กด Enter
เสร็จแล้วให้เราไป Restart Services Print Spooler จากนั้นก็เข้าไป Add Print แบบปกติจะรอนานหน่อยต้องรอจนกว่าจะเสร็จแล้วก็ Add Dirver เข้าไปตามชื่อ Printer ครับ

ตัวอย่าง
https://www.youtube.com/watch?v=XouW14RUJxs

1/17/2022

PHP : php ส่งค่าออก Libreoffice Calc ด้วย TBS

PHP : php ส่งค่าออก Libreoffice Calc ด้วย TBS
ตัวอย่าง
https://www.tinybutstrong.com/opentbs.php?demo

ต้องการส่งค่า ตั้งค่า ใน Template
1. Sting ใช้เป็น [Block.ArrayName]
2. Date ต้องใส่ ;ope=tbs:date ต่อท้าย เช่น [Block.ArrayDate;ope=tbs:date]
3. Number ต้องใส่ ;ope=tbs:num ต่อท้าย เช่น [Block.ArrayDate;ope=tbs:num]
ข้อ 2, 3 ก็จะไม่มี ' และจัด Format ได้
4. ต้องการใส่เลข Run Line ใช้ #;ope=tbs:num ต่อท้าย เช่น [Block.#;ope=tbs:num]

11/17/2021

Axapta : Job เช็ค Item Id 12 หลักและแปลงหลักสุดท้ายให้ถูก

 Axapta : Job เช็ค Item Id 12 หลักและแปลงหลักสุดท้ายให้ถูก

  1.  
  2. static void CheckItemId12(Args _args)
  3. {
  4.     AsciiIO             myFile;
  5.     AsciiIO             ItemFileConvert;
  6.     AsciiIO             ErrorFile;
  7.  
  8.     container           RecData;
  9.     container           contTmp;
  10.  
  11.     ItemId              myItemId;
  12.     ItemId              myItemIdConverted;
  13.     int                 r = 1;
  14.  
  15.     int                 a,b,c,d,e,f,g,h,i,j,k,l;
  16.     int                 a3,b3,c3,d3,e3,f3,g3,h3,i3,j3,k3,l3;
  17.     int                 a4,b4,c4,d4,e4,f4,g4,h4,i4,j4,k4,l4;
  18.     ;
  19.  
  20.     myFile=new AsciiIO("C:\\Item\\ItemCheckConvert.csv","r");
  21.     myfile.inFieldDelimiter("|");
  22.     while(myFile.status() == IO_Status::Ok)
  23.         RecData += myFile.read();
  24.     myFile = null;
  25.  
  26.  
  27.     ItemFileConvert=new AsciiIO("C:\\Item\\ItemFileConvert.txt","a");
  28.     ErrorFile=new AsciiIO("C:\\Item\\ErrorFile.txt","a");
  29.     for(r=1; r <= conlen(RecData); r++){
  30.  
  31.         myItemId =  conpeek(RecData, r);
  32.  
  33.         if(strlen(myItemId) == 12){
  34.             a = str2int(substr(myItemId,1,1));
  35.             b = str2int(substr(myItemId,2,1));
  36.             c = str2int(substr(myItemId,3,1));
  37.             d = str2int(substr(myItemId,4,1));
  38.             e = str2int(substr(myItemId,5,1));
  39.             f = str2int(substr(myItemId,6,1));
  40.             g = str2int(substr(myItemId,7,1));
  41.             h = str2int(substr(myItemId,8,1));
  42.             i = str2int(substr(myItemId,9,1));
  43.             j = str2int(substr(myItemId,10,1));
  44.             k = str2int(substr(myItemId,11,1));
  45.             l = str2int(substr(myItemId,12,1));
  46.  
  47.             a3 = (a * 2);
  48.             b3 = b;
  49.             c3 = (c * 2);
  50.             d3 = d;
  51.             e3 = (e * 2);
  52.             f3 = f;
  53.             g3 = (g * 2);
  54.             h3 = h;
  55.             i3 = (i * 2);
  56.             j3 = j;
  57.             k3 = (k * 2);
  58.  
  59.             a4 = (a3>9) ? str2int(substr(int2str(a3),1,1)) + str2int(substr(int2str(a3),2,1)) : a3;
  60.             b4 = (b3>9) ? str2int(substr(int2str(b3),1,1)) + str2int(substr(int2str(b3),2,1)) : b3;
  61.             c4 = (c3>9) ? str2int(substr(int2str(c3),1,1)) + str2int(substr(int2str(c3),2,1)) : c3;
  62.             d4 = (d3>9) ? str2int(substr(int2str(d3),1,1)) + str2int(substr(int2str(d3),2,1)) : d3;
  63.             e4 = (e3>9) ? str2int(substr(int2str(e3),1,1)) + str2int(substr(int2str(e3),2,1)) : e3;
  64.             f4 = (f3>9) ? str2int(substr(int2str(f3),1,1)) + str2int(substr(int2str(f3),2,1)) : f3;
  65.             g4 = (g3>9) ? str2int(substr(int2str(g3),1,1)) + str2int(substr(int2str(g3),2,1)) : g3;
  66.             h4 = (h3>9) ? str2int(substr(int2str(h3),1,1)) + str2int(substr(int2str(h3),2,1)) : h3;
  67.             i4 = (i3>9) ? str2int(substr(int2str(i3),1,1)) + str2int(substr(int2str(i3),2,1)) : i3;
  68.             j4 = (j3>9) ? str2int(substr(int2str(j3),1,1)) + str2int(substr(int2str(j3),2,1)) : j3;
  69.             k4 = (k3>9) ? str2int(substr(int2str(k3),1,1)) + str2int(substr(int2str(k3),2,1)) : k3;
  70.             l4 = 10 -((a4 + b4 + c4 + d4 + e4 + f4 + g4 + h4 + i4 + j4 + k4) mod 10);
  71.             l4 =( l4 == 10 ) ? 0 : l4;
  72.             if(l4 != l){
  73.                 //Converted
  74.                 myItemIdConverted = strfmt("%1%2%3%4%5%6%7%8%9%10%11%12",a,b,c,d,e,f,g,h,i,j,k,l4);
  75.                 Print(strfmt("%1 : %2 \t Coverted", r, myItemid));
  76.                 ItemFileConvert.write(strfmt("%1|%2", myItemId, myItemIdConverted));
  77.             } else {
  78.                 //Not Convert
  79.                 Print(strfmt("%1 : %2 \t Not Convert", r, myItemid));
  80.                 ItemFileConvert.write(strfmt("%1|%2", myItemId, myItemId));
  81.             }//Close Else.
  82.         } else {
  83.             Print(strfmt("%1 : %2 \t Error", r, myItemid));
  84.             ErrorFile.write(strfmt("%1",myItemId));
  85.         }//Close Else.
  86.     }//Close for.
  87.     ItemFileConvert = null;
  88.     ItemFileConvert = null;
  89.     box::info("Complete","Converted");
  90. }

10/11/2021

Code Auto Remove Slack เปลี่ยน API ใหม่ Code เดิมลบไม่ได้

Python Auto Remove Slack Chet History.

 เปลี่ยน API

  1. response = sc.api_call('conversations.history', channel=channel, limit=1000, oldest=oldest_ts, latest=latest_ts)


Code สำเร็จ
  1.  
  2.  
  3. from slackclient import SlackClient
  4. #from time import sleep
  5. import time
  6. #import datetime
  7. from datetime import datetime, timedelta
  8.  
  9. legacy_token = 'XXXX'  # don't if you share your code
  10. ########## Chanel Camera ##############
  11. channel = 'XXXX'  # Camera Channel.
  12.  
  13. sc = SlackClient(legacy_token)
  14. response = sc.api_call('channels.info', channel=channel)
  15.  
  16. #oldest_ts = response['channel']['created']
  17. date_days_ago = datetime.now() - timedelta(days=90)
  18. oldest_ts = time.mktime(date_days_ago.timetuple())
  19. print(datetime.fromtimestamp(oldest_ts))
  20.  
  21. #date_days_ago = datetime.now() - timedelta(days=60) # Keep File On Slack 60 Day.
  22. date_days_ago = datetime.now() - timedelta(days=7) # Keep File On Slack 7 Day.
  23. latest_ts = time.mktime(date_days_ago.timetuple())
  24. print(datetime.fromtimestamp(latest_ts))
  25.  
  26. #response = sc.api_call('channels.history', channel=channel, count=1000, oldest=oldest_ts, latest=latest_ts)
  27. response = sc.api_call('conversations.history', channel=channel, limit=1000, oldest=oldest_ts, latest=latest_ts)
  28. allmsgs = [item['ts'] for item in response['messages']]
  29. print(len(allmsgs))
  30. for msg in allmsgs:
  31.     sc.api_call('chat.delete', channel=channel, ts=msg)
  32.     time.sleep(1)
  33.  
  34. ########### Chanel Server  ###################
  35. channel = 'XXXXX' # Server Channel.
  36.  
  37. sc = SlackClient(legacy_token)
  38. response = sc.api_call('channels.info', channel=channel)
  39.  
  40. #oldest_ts = response['channel']['created']
  41. date_days_ago = datetime.now() - timedelta(days=90)
  42. oldest_ts = time.mktime(date_days_ago.timetuple())
  43. print(datetime.fromtimestamp(oldest_ts))
  44.  
  45. date_days_ago = datetime.now() - timedelta(days=60)
  46. latest_ts = time.mktime(date_days_ago.timetuple())
  47. print(datetime.fromtimestamp(latest_ts))
  48. #response = sc.api_call('channels.history', channel=channel, count=1000, oldest=oldest_ts, latest=latest_ts)
  49. response = sc.api_call('conversations.history', channel=channel, limit=1000, oldest=oldest_ts, latest=latest_ts)
  50. allmsgs = [item['ts'] for item in response['messages']]
  51. print(len(allmsgs))
  52. for msg in allmsgs:
  53.     sc.api_call('chat.delete', channel=channel, ts=msg)
  54.     time.sleep(1)