หน้าเว็บ

วันพฤหัสบดีที่ 5 เมษายน พ.ศ. 2561

Axapta :: ใส่สี Control ใน Grid

Axapta :: ใส่สี Control ใน Grid

It is possible to use colours in grids on Axapta forms. This can be a useful method to highlight particular rows, or grid cells within a row, based on the data in the record.
Highlighting complete rows
The method .displayOption() method on a form datasource can be over-ridden to control the appearance of an single row in a grid. It is possible to set the background or foreground (text) colour. Since this is a form datasource method, the FormRowDisplayOption affects not only the grid, but also the other controls on this form connected to the datasource.

    public void displayOption(Common _record, FormRowDisplayOption _options)
    {
        _options.backColor(WinApi::RGB2int(255,0,0)); // red 
    }


Highlighting individual grid cells
To highlight one or more individual cells, use the ._options.affectedElementsByControl() method to limit the effect to only the cells in which you are interested.

Note that while this method can display the same colour in multiple cells, there is no way to display different colours in a single row.

    public void displayOption(Common _record, FormRowDisplayOption _options)
    {
        _options.backColor(WinApi::RGB2int(255,255,0)); // Yellow 
        _options.affectedElementsByControl(Control_Name.id());
        _options.affectedElementsByControl(Another_Control_Name.id());
    }

ต้องกำหนด Properties ใน Field ตรง AutoDeclaration เป็น Yes ด้วย
เช่น
public void displayOption(Common _record, FormRowDisplayOption _options)
{
    InventJournalTrans  myInventJournalTrans = _record;

    ;
    super(_record, _options);

    if(myInventJournalTrans.OrderQty != (myInventJournalTrans.Qty * -1)){
        _options.textColor(WinApi::RGB2int(255, 0, 0)); // Red
        _options.affectedElementsByControl(InventJournalTrans_Qty.id());
    }
}

http://www.axaptapedia.com/Using_colours_in_grids

วันอังคารที่ 3 เมษายน พ.ศ. 2561

Axapta : Update ต้นทุนค่าแรงเมื่อเพิ่มเงินเดือนพนักงาน

ต้องทำใน Local ก่อน และ Backup ข้อมูลทั้ง Table ในของจริงก่อนจะเอาเข้า
1. Up แบบ Import File ทำไฟล์ แล้วเอาเข้ากรณีเพิ่มใหม่หรือยังไม่มี MC
https://intranet.sci.com/blog.php?u=578&b=1129

2. แบบมี ข้อมูลอยู่แล้วแต่ต้องการ Update ค่าแรง ใช้ Code ทำเป็น Job Run ทำไฟล์ โดยใช้ EmpId,ต้นทุนค่าแรง
Code

    static void UpdateCostcategoryOT(Args _args)
    {
            AsciiIO             myFile;
            AsciiIO             OKFile;
            AsciiIO             NOFile;
            int                 i,n;
            int                 intRecId;
            container           RecData;
            container           contTmp;
            ItemId              myMC;
            EmplId              myEmplId;
            Price               myCost;
            InventTable         inventTable;
            RouteCostCategory   routeCostCategory;
   
            ;
   
            myFile=new AsciiIO("D:\\2018_Update.csv","r");
            myfile.inFieldDelimiter(",");
            while(myFile.status() == IO_Status::Ok)
                RecData += myFile.read();
            myFile = null;
   
   
            OKFile=new AsciiIO("D:\\OK-Update.txt","a");
            NOFile=new AsciiIO("D:\\NO-Update.txt","a");
            for(i=1; i <= conlen(RecData); i++){
   
                myCost =  conpeek(RecData, i);
                i++;
                myEmplId =  conpeek(RecData, i);
   
                SELECT * FROM routeCostCategory
                WHERE routeCostCategory.EmplId == myEmplId;
   
                if(routeCostCategory.RecId){
                    //print(strfmt("%1 : %2 \t OK",i,myEmplId));
                    OKFile.write(strfmt("%1\t%2\t%3",myEmplId, routeCostCategory.CostPrice, myCost));
                    ttsbegin;
   
    // #####  Cost Amount ######
                    WHILE
                    SELECT FORUPDATE * FROM routeCostCategory
                    WHERE routeCostCategory.EmplId == myEmplId
                    {
                        routeCostCategory.CostPrice = myCost;
                        routeCostCategory.update();
                    }
    // #####  Cost Amount OT 1.5 ######
                    WHILE
                    SELECT FORUPDATE * FROM routeCostCategory
                    WHERE routeCostCategory.EmplId == myEmplId
                    && (routeCostCategory.CostCategoryId LIKE '*1.5' || routeCostCategory.CostCategoryId LIKE 'OT1.5*')
                    {
                        routeCostCategory.CostPrice = myCost * 1.5;
                        routeCostCategory.update();
                    }
    // #####  Cost Amount OT 2.0 ######
                    WHILE
                    SELECT FORUPDATE * FROM routeCostCategory
                    WHERE routeCostCategory.EmplId == myEmplId
                    && (routeCostCategory.CostCategoryId LIKE '*2.0' || routeCostCategory.CostCategoryId LIKE 'OT2.0*')
                    {
                        routeCostCategory.CostPrice = myCost * 2.0;
                        routeCostCategory.update();
                    }
    // #####  Cost Amount OT 3.0 ######
                    WHILE
                    SELECT FORUPDATE * FROM routeCostCategory
                    WHERE routeCostCategory.EmplId == myEmplId
                    && (routeCostCategory.CostCategoryId LIKE '*3.0' || routeCostCategory.CostCategoryId LIKE 'OT3.0*')
                    {
                        routeCostCategory.CostPrice = myCost * 3.0;
                        routeCostCategory.update();
                    }
                    ttscommit;
   
                }else{
                    //print(strfmt("%1 : %2 \t NO",i,myEmplId));
                    NoFile.write(strfmt("%1,%2",myEmplId, myCost));
                }
   
   
   
            }
            OKFile = null;
            NOFile = null;
            box::info(" Complete","File2SQL");
    //    pause;
   
    }



3. เปลี่ยนแท่นเปลี่ยนคน ต้องทำ
3.1. ได้ไฟล์มาทำไฟล์ เอารหัสพนักงานเข้าไป Check ว่ามีพนังานอยู่หรือไม่ ถ้าไม่มีตรวจสอบอาจใส่รหัสผิด หรือต้องเพิ่มข้อมูลใหม่ในข้อ 1.
ใช้ MC,EmpId
Code

    static void UpdateCostcategoryCheckMC(Args _args)
    {
            AsciiIO             myFile;
            AsciiIO             OKFile;
            AsciiIO             NOFile;
            int                 i,n;
            int                 intRecId;
            container           RecData;
            container           contTmp;
            ItemId              myMC;
            EmplId              myEmplId;
            Price               myCost;
            InventTable         inventTable;
            RouteCostCategory   routeCostCategory;
   
            ;
   
            myFile=new AsciiIO("D:\\CheckMC.csv","r");
            myfile.inFieldDelimiter(",");
            while(myFile.status() == IO_Status::Ok)
                RecData += myFile.read();
            myFile = null;
   
   
            OKFile=new AsciiIO("D:\\CheckMCOK.txt","a");
            NOFile=new AsciiIO("D:\\CheckMCNO.txt","a");
            for(i=1; i <= conlen(RecData); i++){
   
                myMC =  conpeek(RecData,i);
                i++;
                myEmplId =  conpeek(RecData,i);
   
                SELECT * FROM routeCostCategory
                WHERE routeCostCategory.CostCategoryId == myMC;
                if(routeCostCategory.RecId){
                    print(strfmt("%1 : %2 \t OK",i,myEmplId));
                    OKFile.write(strfmt("%1\t%2\t%3",myMC, myEmplId, routeCostCategory.EmplId));
                    /*ttsbegin;
                    WHILE SELECT FORUPDATE * FROM routeCostCategory
                    WHERE routeCostCategory.EmplId == myEmplId
                    {
                    routeCostCategory.CostPrice = myCost;
                    routeCostCategory.update();
                    }
                    ttscommit;*/
                }else{
                    print(strfmt("%1 : %2 \t NO",i,myEmplId));
                    NoFile.write(strfmt("%1,%2",myMC, myEmplId));
                }
   
   
   
            }
            OKFile = null;
            NOFile = null;
            box::info(" Complete","File2SQL");
    //    pause;
   
    }


3.2. ได้ไฟล์ที่จะ Update เปลี่ยนแท่น Format : MC,EmpId,EmpIdAX เขียน Code Update เปลี่ยนแท่น จะเปลี่ยนจาก Emp อีกคนเป็นอีกคน ทุก รายการที่ MC เดียวกัน แล้วค่อยไป Update ค่าแรงในข้อ 2.
Code    
    static void UpdateCostcategoryMC(Args _args)
    {
            AsciiIO             myFile;
            AsciiIO             OKFile;
            AsciiIO             NOFile;
            int                 i,n;
            int                 intRecId;
            container           RecData;
            container           contTmp;
            ItemId              myMC;
            ItemId              myMCUpdate;
            EmplId              myEmplId;
            EmplId              myEmplIdAX;
            Price               myCost;
            InventTable         inventTable;
            RouteCostCategory   routeCostCategory;
   
            ;
   
            myFile=new AsciiIO("D:\\UpdateMC.csv","r");
            myfile.inFieldDelimiter(",");
            while(myFile.status() == IO_Status::Ok)
                RecData += myFile.read();
            myFile = null;
   
            OKFile=new AsciiIO("D:\\UpdateMCOK.txt","a");
            NOFile=new AsciiIO("D:\\UpdateMCNO.txt","a");
            for(i=1; i <= conlen(RecData); i++){
   
                myMC = conpeek(RecData,i);
                i++;
                myEmplId =  conpeek(RecData,i);
                i++;
                myEmplIdAX =  conpeek(RecData,i);
   
                myMCUpdate = strfmt('*%1*', myMC);
                ttsbegin;
                WHILE
                SELECT FORUPDATE * FROM routeCostCategory
                WHERE routeCostCategory.EmplId == myEmplIdAX
                    && routeCostCategory.CostCategoryId LIKE myMCUpdate
                {
                    if(routeCostCategory.RecId){
   
                        //print(strfmt("%1 : %2 \t OK",i,myEmplId));
                        OKFile.write(strfmt("%1\t%2\t%3",myMC, myEmplId, myEmplIdAX));
   
                        routeCostCategory.EmplId = myEmplId;
                        routeCostCategory.update();
                    } else {
                        //print(strfmt("%1 : %2 \t NO",i,myEmplId));
                        NoFile.write(strfmt("%1,%2",myMC, myEmplId, myEmplIdAX));
                    }
                }
                ttscommit;
            }
            OKFile = null;
            NOFile = null;
            box::info(" Complete","File2SQL");
    //    pause;
   
    }



4.พนักงานออกไปแล้ว เขียน Code Reset รหัสและค่าแรง โดยเปลี่ยนรหัสพนักงาน
Code

    static void UpdateCostcategoryByEmpId(Args _args)
    {
            EmplId              myEmplId;
            Price               myCost;
            InventTable         inventTable;
            RouteCostCategory   routeCostCategory;
   
            ;
   
            ttsbegin;
                WHILE SELECT FORUPDATE * FROM routeCostCategory
                WHERE routeCostCategory.EmplId == '4273-5'
                {
                routeCostCategory.EmplId = '';
                routeCostCategory.CostPrice = 0;
                routeCostCategory.update();
                }
            ttscommit;
   
            box::info(" Complete","File2SQL");
    }

วันพฤหัสบดีที่ 29 มีนาคม พ.ศ. 2561

QNAP : QNAP เครื่องกล้องวงจรปิด ไม่แสดง Desktop แต่ขึ้นเป็น หน้าจอ Terminal

QNAP : QNAP เครื่องกล้องวงจรปิด ไม่แสดง Desktop แต่ขึ้นเป็น หน้าจอ Terminal แทน
เกิดจาก โปรแกรม HD Station ไม่ทำงาน อาจะถูก Disable หรือUpdate แล้วมีปัญหา

แก้โดย
- Update HD Station หรือ Enable Program HD Station แล้ว Restart เครื่อง ก็จะใช้งานได้ตามปกติ

วันอังคารที่ 27 มีนาคม พ.ศ. 2561

Zimbra : Zimbra mails going to Junk folder

Zimbra : Zimbra mails going to Junk folder

Use Command
  1. zmlocalconfig -e amavis_dspam_enabled=true

for
  1. zmlocalconfig -e amavis_dspam_enabled=false


https://forums.zimbra.org/viewtopic.php?t=19065

Python : Python ส่งค่าเข้า MQTT

Python : Python ส่งค่าเข้า MQTT
  1.        # Start MQTT #
  2.         import paho.mqtt.client as mqtt
  3.  
  4.         mqttc = mqtt.Client("python_pub")
  5.         mqttc.connect("192.168.2.200", 1883)
  6.         mqttc.publish("hass/temperature_server_A", temperature)
  7.         mqttc.loop(2) #timeout = 2s
  8.  
  9.         # End MQTT #


Error ImportError: No module named paho.mqtt.client
  1. root@raspberrypi:/home/pi# python mqtt.py
  2. Traceback (most recent call last):
  3.   File "mqtt.py", line 21, in <module>
  4.     import paho.mqtt.client as mqtt
  5. ImportError: No module named paho.mqtt.client


  1. sudo apt-get install python-pip
  1. pip install paho-mqtt



คำสั่งพื้นฐาน

ดูสถานะ error สามารถใช้ start stop restart status
ไว้ Restart ถ้า Restart ผ่านหน้า Web แล้วไม่ทำงาน
  1. sudo systemctl status home-assistant@homeassistant


Python Auto Start Background On Pi

  1. chmod 755 /etc/rc.local

add before "exit 0"
  1. (sleep 10;sudo python /home/pi/mqttAir.py) &

Proxy :: Ubuntu Proxy Disk Root Full

Proxy :: Ubuntu Proxy Disk Root Full
Simple Ways To Free Up Space on Ubuntu
1. remove linux-headers
  1. sudo apt autoremove


2. Clean cache
  1. sudo apt-get autoclean


To

วันอังคารที่ 6 มีนาคม พ.ศ. 2561

Zimbra : Zimbra zmbkpose Backup Active User

Zimbra : Zimbra zmbkpose Backup Active User
https://wiki.zimbra.com/wiki/Create_a_distribution_list_that_contains_all_the_addresses_in_a_domain

1. แก้ Code ที่ /usr/bin
  1. nano /usr/bin/zmbkpose

2. หา Function 3 ตัวนี้
backup_all_accounts ()
incremental_all_accounts ()
backup_all_accounts_parallel()

แก้
  1. "(objectClass=zimbraAccount)"

เป็น
  1. "(&(objectClass=zimbraAccount)(ZimbraAccountStatus=active))"

3. ZimbraAccountStatus สามารถใส่ค่าที่เราต้องการได้
Active, Closed, Locked, Pending, Maintenance
ข้อมูลก็จะได้ไฟล์ และ sessions.txt ก็เฉพาะ User ที่เราเลือกตาม Status ไว้ตรงตาม ZimbraAccountStatus