Feeds:
Posts
Comments

Dear All,

Met ketemu lagi dalam acara Delphi Coderz … :mrgreen:

Kemarin, ada dari temen bro @ImanD mengenai bagaimana memunculkan gambar bukan dari database saja, akan tetapi dari file juga, soalnya kita pengguna Developer Express Quantum Grid.

Setelah membaca dan mengurai dari keterangan Knowledge Basenya Developer Express. Akhirnya bisa ditampilkan apa yang diinginkan … sebelumnya mah udah jalan tapi gak bisa munclu gambarnya :mrgreen:

Nah, sekarang daripada ngomong gak karuan langsung saja, kita buat project baru dan simpan deh komponen yang diperlukan seperti zConnection, zTable (karena pake ZeosLib), DataSource dan cxGridnya.

Untuk di gridnya ditambahkan 1 column unbound, jadi dikenal dengan column cxGrid1DBTableView1Column1, dengan set properties :

cxGrid1DBTableView1Column1.Properties := Images
.Properties.Images.GraphicClassName := TJPEGImage
.Properties.Images.ImmediatePost := true

sekarang untuk Databindingnya di set ke:

cxGrid1DBTableView1Column1.DataBinding.ValueType := string

untuk DataBinding.FieldName nya di kosyonk an saja, karena ini tidak dipakai, jadi column ini disebut unbound data-aware.

Sekarang … Codingz , tadi nya saya pikir bisa disimpan pada event onCustomDrawCell, karena untuk masalah beda warna tiap baris bisa digunakan event ini, tapi ternyata terjadi infinite-loop pada event Paint nya DevexGrid.

Jadi, saya tempatkan pada event : onGetProperties dari cxGrid1DBTableView1Column1 dengan isi :

procedure TForm8.cxGrid1DBTableView1Column1GetProperties(
  Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
  var AProperties: TcxCustomEditProperties);
var
  AFileName, AValue: String;
  APicture: TPicture;
begin
  AFileName := 'C:\Manz\Projects\Web\hrms\public_html\images\photo\' +
               VarToStr(ARecord.Values[cxGrid1DBTableView1nip.Index]) + '.jpg';
  if (fileexists(AFileName)) then
  begin
    APicture := TPicture.Create;
    try
      APicture.LoadFromFile(AFileName);
      SavePicture(APicture, AValue);
    finally
      freeAndNil(APicture);
    end;
  end
  else AValue := '';

  cxGrid1DBTableView1.DataController.Values[ARecord.RecordIndex, Sender.Index] := AValue;
end;


Dengan hasil snap-shot diatas .. maka hasil yang di-inginkan keluar seperti ini :mrgreen:

ImageLoad

ada 2 field tertera diatas, yaitu from DB dan from File, nah yang from File inilah yang disebut dengan unbounded data-aware.

Dikau temanz .. bisa mencoba nya … any error, any mistake (salah), access denied or error yang laindon’t ask … alias jangan tanya … silahkan trace sendiri sajah yah … :mrgreen:

Seperti biasa, kalau code ini berguna untuk kalian teman-temanz, teman-temanz bisa donate kepadaku ya ya ya :mrgreen: for keep this blog live and given the some tricky … :mrgreen:

Salam Coderz,
8-)
Man’z

procedure TForm8.cxGrid1DBTableView1Column1GetProperties(
Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
var AProperties: TcxCustomEditProperties);
var
AFileName, AValue: String;
APicture: TPicture;
begin
AFileName := ‘C:\Manz\Projects\Web\hrms\public_html\images\photo\’ +
VarToStr(ARecord.Values[cxGrid1DBTableView1nip.Index]) + ‘.jpg’;
if (fileexists(AFileName)) then
begin
APicture := TPicture.Create;
try
APicture.LoadFromFile(AFileName);
SavePicture(APicture, AValue);
finally
freeAndNil(APicture);
end;
end
else AValue := ”;

cxGrid1DBTableView1.DataController.Values[ARecord.RecordIndex, Sender.Index] := AValue;
end;

Dear All, again MySQL again…hehehehe … simple trick from me that will save your time of work when you using looping in code … yeah code … in Delphi, VB, what ever you create the aplication.

We will trying to create crosstab or whatever you will said … in MySQL …

First, saya punya data sebagai berikut :

Tabel karyawan:
 NIP   | Nama
 ------------------------
 001   | Udin tea
 002   | Budi Kahandap
 003   | Andi Kararangge
 004   | Cecep Gorbacep
 005   | Ono Ontohod 

 Tabel master_absen:
 tipe_absen | deskripsi
 ----------------------
 AL         | ALPA
 SK         | SAKIT
 CT         | CUTI 

 Tabel absen:
 NIP  |     TGL    | tipe_absen
 ------------------------------
 001  | 01/07/2009 | AL
 001  | 02/07/2009 | AL
 002  | 05/07/2009 | CT
 004  | 05/07/2009 | CT
 002  | 06/07/2009 | SK
 003  | 07/07/2009 | SK
 003  | 08/07/2009 | SK
 003  | 09/07/2009 | SK
 003  | 10/07/2009 | SK
 005  | 11/07/2009 | AL
 005  | 12/07/2009 | AL
 005  | 13/07/2009 | AL
 005  | 14/07/2009 | AL

Actually we want to create the result of query like this :

 NIP | NAMA            | AL | CT | SK
 ------------------------------------
 001 | Udin tea        | 2  | 0  | 0
 002 | Budi Kahandap   | 0  | 1  | 0
 003 | Andi Kararangge | 0  | 0  | 4
 004 | Cecep Gorbacep  | 0  | 1  | 0
 005 | Ono Ontohod     | 4  | 0  | 0

Tapi … ada tapinya juga neh …. kalau di master_absen dan di data absen ditambah datanya menjadi :

 tipe_absen | deskripsi
 --------------------------
 AL         | ALPA
 SK         | SAKIT
 CT         | CUTI
 IZ         | IZIN PULANG   <---- tambahan data

kemudian data absen jadi :

 NIP  |     TGL    | tipe_absen
 ------------------------------
 001  | 01/07/2009 | AL
 001  | 02/07/2009 | AL
 002  | 05/07/2009 | CT
 004  | 05/07/2009 | CT
 002  | 06/07/2009 | SK
 003  | 07/07/2009 | SK
 003  | 08/07/2009 | SK
 003  | 09/07/2009 | SK
 003  | 10/07/2009 | SK
 005  | 11/07/2009 | AL
 005  | 12/07/2009 | AL
 005  | 13/07/2009 | AL
 005  | 14/07/2009 | AL
 003  | 20/07/2009 | IZ    <--- tambahan data
 004  | 21/07/2009 | IZ    <--- tambahan data

hasil yang diinginkan jadi :

 NIP | NAMA            | AL | CT | IZ | SK
 -----------------------------------------
 001 | Udin tea        | 2  | 0  | 0  | 0
 002 | Budi Kahandap   | 0  | 1  | 0  | 0
 003 | Andi Kararangge | 0  | 0  | 1  | 4
 004 | Cecep Gorbacep  | 0  | 1  | 1  | 0
 005 | Ono Ontohod     | 4  | 0  | 0  | 0

Nah ada tambahan kolom IZ tuh ….

Sekarang, How to make the simple single query statements ? yeah … query statements …

This below is step … step by step we will describe it …

Kalau kita menggunakan sql query dengan link left join seperti biasa :

select k.nip, k.nama, a.tipe_absen, a.tgl
from karyawan k
left join absen a on k.nip = a.nip
left join master_absen m on a.tipe_absen = m.tipe_absen
group by k.nip, a.tgl
order by k.nip

we got result like this :

Query 1

Nah itu baru memunculkan semua data yang ada.

Sekarang kita coba di otak atik sql nya dengan menggunakan power of group_concat dan select concat statement dan menjadi sql kita, untuk mendapatkan hasil berapa banyak si-dia absen dan tidak menghiraukan tanggal berapa saja, dan saya tidak akan menjelaskan untuk group_concat and select concat functions disini, bukan gag mau … tapi cape ngetiknya :mrgreen: , seperti dibawah ini :

select concat(
'select k.nip, k.nama',
group_concat(
concat(', sum(if(a.tipe_absen="', m.tipe_absen, '", 1, 0)) As ', m.tipe_absen, '\n')
order by m.tipe_absen separator ''),
'from karyawan k
left join absen a on k.nip = a.nip
left join master_absen m on a.tipe_absen = m.tipe_absen
group by k.nip, m.tipe_absen
order by k.nip, m.tipe_absen') into @Absence_SQL
from master_absen m;
prepare Absences from @Absence_SQL;
execute Absences;

Nah, disini kita sudah menggunakan fitur statement dari MySQL, dan juga return statement ke variable @Absence_SQL dan kita akan lakukan execute Absences untuk mendapatkan resultset seperti dibawah ini :

Query 2

Tapi … eit … just a moment … we got false data …, jika dilihat … record no 2 dan 3, kan ada 002 untuk Budi Kahandap itu punya status CT dan SK …. gak mungkin untuk memunculkan data seperti ini dan diserahkan kepada yang berwajib … hehehehe :mrgreen:

So, we change again the sql structure to meet our requirements … like shown as below :

select concat(
'select T.nip, T.nama',
group_concat(concat(', sum(T.', m.tipe_absen,') As ', m.tipe_absen, '\n')
order by m.tipe_absen separator ''), '\n',
'from (select k.nip, k.nama',
group_concat(
concat(', sum(if(a.tipe_absen="', m.tipe_absen, '", 1, 0)) As ', m.tipe_absen, '\n')
order by m.tipe_absen separator ''),
'from karyawan k
left join absen a on k.nip = a.nip
left join master_absen m on a.tipe_absen = m.tipe_absen
group by k.nip, m.tipe_absen
order by k.nip, m.tipe_absen) As T
group by T.nip') into @Absence_SQL
from master_absen m;
prepare Absences from @Absence_SQL;
execute Absences;

Nah, so … after we concatenate the sql statements again .. what we got ???

You may see what we want … as shown below :

Query 3

Ow, … we got right what we want …. records no 2 has become one line … :mrgreen:

ck… ck… ck… just a moment … but how we added the data has been described in beginning of this post ?

Just insert the data at master_absen and data absen … and then … just running again the last sql statements, and you will get the results like this :

Query 4

Look at the columns … somethin’ differents 8-) between this result of query than before  ??? You decide :mrgreen:

Dikau friendz bisa mengubah – ubah query diatas sesuai dengan keinginan ….

Sampai jumpa di lain Query Tricky. Oh ya… don’t forget to donate :mrgreen: to make this blog live and give another tricky … :mrgreen:

Salam DBA,
8-)
Man’z

Dear all, met me again …

Now, we will posting how to resolve when your MySQL Server make you headache … alias bikin sakit kepala dan mau pecah … karena MySQL menolak semua access dari all host and IP.

Actually we don’t know what this happen persist, teuing kunaon tah … langsung begitu gag mau terima koneksi dari host manapun …. dan muncul salah satu pesan seperti ini :

ERROR 1130 (HY000): Host ‘localhost’ is not allowed to connect to this MySQL server.

atawa:

ERROR 1130 (HY000): Host ‘manz’ is not allowed to connect to this MySQL server.

atawa:

ERROR 1130 (HY000): Host ‘192.168.1.200′ is not allowed to connect to this MySQL server.

But … don’t worry … be happy :D i already found the technique to resolve this problem … :mrgreen:

We don’t know if other site already mention …

Teknik ini saya pakai karena server saya menggunakan windows …

Langkah – langkah nya :

1. Matikan service dari MySQL :

net stop MySQL

2. Jalankan service dengan background dan skipping checking user and privilege table:

start /b mysqld –skip-grant-tables –user=root

3. Reset user table di mysql dengan memanggil mysql command:

mysql -e “insert into mysql.user(host, user, grant_priv, super_priv, ssl_cipher, x509_issuer, x509_subject) values(’root’,'%’,'Y’,'Y’,”,”,”);”

4. Kemudian matikan MySQL yang jalan di background process tersebut:

mysqladmin -uroot shutdown

5. Jalankan service MySQL secara normal:

net start MySQL

After that , ta..da…. dikau bisa masuk ke MySQL lagi, kalo anda tidak reset password, anda bisa pake password yang lama.

Silahkan mencicipi … :mrgreen:

Salam DBA,
8-)
Man’z

Dear All readers,

Back again with “Ngitung Balance” … :mrgreen:

Pada postingan dulu, saya melakukan perhitungan balance dengan menggunakan fitur yang ada FastReport dan silahkan baca disini untuk balance FastReport.

Nah, sekarang bagaimana ngitung balance dengan menggunakan MySQL atau Single Simple Query ?

Setelah sekian waktu mencoba, mengutak – mengatik … dan akhirnya ketemu dengan simple.

Silahkan coba dengan membuat table seperti ini :

CREATE TABLE accountdeposit
(
  id INTEGER(11) NOT NULL AUTO_INCREMENT,
  memCode CHAR(9) COLLATE latin1_swedish_ci NOT NULL,
  transCode CHAR(100) COLLATE latin1_swedish_ci NOT NULL,
  stat ENUM('D','C') NOT NULL,
  balance FLOAT(9,3) NOT NULL,
  transDate TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP
            DEFAULT CURRENT_TIMESTAMP,
  author INTEGER(11) NOT NULL, PRIMARY KEY (id),
  KEY memCode (memCode)
);
INSERT INTO accountdeposit (id, memCode, transCode, stat, balance,
                            transDate, author) VALUES
(5, '0321001', 'Buka Account', 'C', 100000, '2009-03-21 00:05:44', 1),
(6, '0321001', 'open list 3 Form', 'D', 15000, '2009-03-23 10:51:16', 1),
(7, '0321001', 'open list 4 Form', 'C', 20000, '2009-03-23 13:05:00', 1);
COMMIT;

Nah, itu untuk struktur dan data nya … itu diatas mah sample doank ya … :mrgreen:

Sekarang bagaimana untuk retrieve agar mendapatkan seperti dibawah ini ?

+------------------+------------+------------+-------------+
| transCode        | Debit      | Credit     | LastBalance |
+------------------+------------+------------+-------------+
| Buka Account     |      0.000 | 100000.000 |  100000.000 |
| open list 3 Form | -15000.000 |      0.000 |   85000.000 |
| open list 4 form |      0.000 |  20000.000 |  105000.000 |
+------------------+------------+------------+-------------+

Nih dibawah sql scriptnya :

select transCode,
case when stat='D' then (-balance) else 0 end as Debit,
case when stat='C' then balance else 0 end as Credit,
(@LB := @LB + if (stat='D', -balance, balance)) as LastBalance
from (select @LB := 0) as LastBlnc, accountdeposit
where memCode = '0321001'
group by memcode, transdate
order by transdate;

Hasilnya ? ya seperti diatas …

Thanks to bro @yayaretina that has been open my mind to create a Simple Single Queries .. :mrgreen:

Cheers,
8-)
Man’z

Dear All,

Once again, MySQL make me headache to handle un-linked key that consist at temporary tables and this two table is manipulate by record-form model.

This is a scenario :

We’ve 2 table — simple table that want to inserting the key for linked between that tables, that the key from master table is generated from trigger.

for example :

create table tbl_a
(
  uid varchar(40) default '-',
  name varchar(50),
  constraint pk_tbl_a primary key (uid)
);

create table tbl_b
(
  uid varchar(40),
  qty double precision default 0,
  description varchar(100),
  constraint fk_tbl_b foreign key (uid)
    references tbl_a (uid)
    on update cascade on delete cascade
);

now, we create the trigger for this table a.

create trigger trig_tbl_a before insert on tbl_a for each row
set new.uid = uuid();

but, how to insert the tbl_b.uid ? if we use simple insert statement … ?

After we long discussed with our best friends … Now, we have one good idea.

This the resolving the problem :

drop and re-create the trigger at table a :

drop trigger trig_tbl_a;
create trigger trig_tbl_a before insert on tbl_a for each row
begin
  set new.uid = uuid();
  create temporary table if not exists t_uid(uid varchar(40));
  delete from t_uid;
  insert into t_uid values (new.uid);
end;

then, create trigger for table b:

create trigger trig_tbl_b before insert on tbl_b for each row
set new.uid = (select uid from t_uid);

after that, we can relate the data on table b using the uid key.

try this :

mysql> insert into tbl_a (name) values ('Manz');
Query OK, 1 row affected, 1 warning (0.03 sec)

mysql> insert into tbl_b (qty, description) values (10, 'Movie ordered with DVD original version');
Query OK, 1 row affected (0.03 sec)

mysql> select * from tbl_a;
+--------------------------------------+------+
| uid                                  | name |
+--------------------------------------+------+
| 4b5a8c27-0321-11de-88cd-184e3e4ece1f | Manz |
+--------------------------------------+------+
1 row in set (0.02 sec)

mysql> select * from tbl_b;
+--------------------------------------+------+-----------------------------------------+
| uid                                  | qty  | description                             |
+--------------------------------------+------+-----------------------------------------+
| 4b5a8c27-0321-11de-88cd-184e3e4ece1f |   10 | Movie ordered with DVD original version |
+--------------------------------------+------+-----------------------------------------+
1 row in set (0.00 sec)

Now, we can use the code to update my uid. And result is my headache is gone…. :mrgreen:

Cheers,
8-)
Man’z

MySQL Grouping Tips

Hai hai … friend … ada kasus dari temen nih, sempet keringetan karena gak ketemu jalan keluarnya, sehingga posting di forum.

Jadi sebagai bahan arsip ajah, saya arsipkan dan siapa tahu ada yang membutuhkannya.

Ini pure di MySQL :

DROP TABLE IF EXISTS `tnama`;
CREATE TABLE `tnama` (
`id` int(11) NOT NULL auto_increment,
`NIK` varchar(10) default NULL,
`Nama` varchar(10) default NULL,
`NoTelp` varchar(10) default NULL,
`Grup` varchar(10) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;

– —————————-
– Records
– —————————-
INSERT INTO `tnama` VALUES (’1′, ‘A’, ‘A’, ‘A’, ‘A’);
INSERT INTO `tnama` VALUES (’2′, ‘A’, ‘A’, ‘A’, ‘B’);
INSERT INTO `tnama` VALUES (’3′, ‘A’, ‘A’, ‘A’, ‘C’);
INSERT INTO `tnama` VALUES (’4′, ‘B’, ‘B’, ‘B’, ‘A’);
INSERT INTO `tnama` VALUES (’5′, ‘B’, ‘B’, ‘B’, ‘B’);
INSERT INTO `tnama` VALUES (’6′, ‘C’, ‘C’, ‘C’, ‘A’);
INSERT INTO `tnama` VALUES (’7′, ‘C’, ‘C’, ‘C’, ‘B’);

hasil dari select biasa adalah :

NIK Nama  NoTelp  Grup
----------------------
A     A     A       A
A     A     A       B
A     A     A       C
B     B     B       A
B     B     B       B
C     C     C       A
C     C     C       B

Nah sekarang pengen hasilnya seperti ini :

NIK Nama  NoTelp  Grup
-------------------------
A    A      A     A,B,C
B    B      B     A,B
C    C      C     A,B

Gimana tuh … sempet saya juga pusyink memikirkan nya , dan ternyata ketemu dengan menggunakan reserved word yang ada di MySQL :mrgreen:

Statement nya :

select nik, nama, telp, group_concat(grup)
from tnama
group by nik

Hasilnya …. sama dengan yang di-ingin-kan ….

Salam DBA,
8-)
Man’z

Dear All,

Now, as per my promise, we’ll show to you, how to create user and monitoring they do.

Just it simply.

1. Create User

Login as SAP* or user has been assigned SAP_ALL profile like shown below :

sap_logon_2

And, after logon to system, find out to create user using t-code SU01 or select from menu tree at : Tools -> Administration -> User Maintenance -> Users, shown like below :

sap_menu_1

And then type the name at the User fields, and push F8 to create the users, show like below :

create_user

After pushing F8 or creating new user, the dialog will shown like this :

create_user_1

Input the Last name (required) and other information at this screens.

Go to Logon data tab, and type the initial password twice. This initial password should be change at first login. Because we trying for create user with full access, type SUPER at User Group for Authorization Object, shown below :

create_user_2

And the go to profile tab, and fill the profile with SAP_ALL and push enter, shown like below :

create_user_3

After all required data has been filled, push save and the screen you may see like this :

create_user_4

2. Users Monitoring

As the super user or user with full priviledges, you may see who’s users login and what they do in our system.

You may use SM04 – Users Overview or using tree menu at : Tools -> Administration -> Monitor -> System Monitoring -> User Overview. Using that t-code will shown like below :

user_monitor

In this sample we shown 2 users online at our system with they transaction code do, and then what they do at our system, just double clicked it at the user online, will shown like this :

user_monitor_1

That’s all falks for user create and monitoring… Have fun ..

Cheers,
8-)
Man’z

Dear all,

For our friends that didn’t know the SAP software is …

Now, we put some simple SAP screen-shot with short descriptions …

before you can login to SAP server, in this example we using IDES, you should create the shortcut logon in SAP GUI with click New Item button on SAP Logon GUI

sap_logon

After that, the system will show New System Entry like this :

new_system_entry

In this entry, you may click new button to create new connection entry system, after click next button, the dialog will show next entry like this :

new_system_entry_1

In this dialog, you have to input 4 fields to describe and connect to SAP server.

1. Descriptions: this make you easy view on the Logon GUI dialog.
2. Application server: fill this field with application server IP address or hostname, if not sure, ask to your administrator or SAP BASIS to know this application entry point address.
3. System number: fill this field with system number of SAP server, if not sure, ask to your administrator or SAP BASIS to know this installed system number.
4. System ID: fill this field with system ID of SAP server, again, if not sure, ask to your SAP administrator or SAP BASIS to know this System ID.

Don’t forget, Choose connection type with : Custom Application Server.

After fill all required fields, click next button to next options dialog, like this :

new_system_entry_2

Netwotk settings for this connection, if you use the secure netwok communication, you should check mark this fields, and fill required SNC name and options.

Also, choose the network setting speeds, for best performance or on Local Network, choose High Speed Connection (LAN), even in actual we use High Speed Connection (LAN) in WAN connections, 512Mbps is enough to use this HS connection, but in my network we use E1 thats mean using 2048Kbps or 2Mbps. :mrgreen: fast enough …

After complete, and change click next button to choose the Language and Upload/Download settings, and click Finish, shown like below :

new_system_entry_3

And system will create entry system connetion shown like this :

sap_logon

Now, you may logon using that system connection.

Next post we will show you the Navigation of SAP GUI.

Cheers,
8-)
Man’z

Dear All,

Just simply change like this :

First, capture the hardware address / mac-address before changing

# ifconfig eth0 | grep HWaddr

After that, do this command :

# ifconfig eth0 down
# ifconfig eth0 hw ether 80:00:27:88:F6:AF
# ifconfig eth0 up

And then, capture again after changing the mac-address

# ifconfig eth0 | grep HWaddr

be aware, this command will be disconnect you LAN/WAN connection, do after connection idle or you know no active connection.

If you use the DHCP server, usually DHCP server will be re-flush the IP client when eth0 up after down or re-forcing from client or the TTL of IP lease is expired.

For forcing new ip before TTL expired, do like this :

# sudo dhclient -r

or

# sudo dhclient

or just more simple

# init.d/rc.d/network restart

That’s all falks ..

Sincerely
8-)
Man’z

tested on virtual ubuntu

Older Posts »