Đề tài Xây dựng chương trình Quản Lý Nhân Sự

MỤC LỤC

 

LỜI NÓI ĐẦU 1

PHẦN I: NỘI DUNG BÀI TOÁN 2

PHẦN II: THIẾT KẾ CHỨC NĂNG 3

PHẦN III: THIẾT KẾ DỮ LIỆU 5

PHẦN IV: THIẾT KẾ MODULE CHƯƠNG TRÌNH 6

PHẦN IV: CÀI ĐẶT VÀ HƯỚNG DẪN SỬ DỤNG CHƯƠNG TRÌNH 7

PHẦN V: KẾT LUẬN 9

PHỤ LỤC 10

 

 

doc33 trang | Chia sẻ: maiphuongdc | Lượt xem: 1472 | Lượt tải: 2download
Bạn đang xem trước 20 trang tài liệu Đề tài Xây dựng chương trình Quản Lý Nhân Sự, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
ện các thao tác như chức năng tạo mới. Chức năng khai thác gồm các chức năng con: Sắp xếp danh sách nhân sự hoặc theo năm sinh, hoặc theo năm lên lương, hoặc theo mức lương(tùy theo sự lựa chọn của người sử dụng). Sau khi sắp xếp có thể dùng phím Page UP Page Down để xem kết quả. Kết quả có thể ghi hoặc không ghi lên tệp(theo sự lựa chọn của người sử dụng) Thống kê danh sách những người đủ thời hạn lên lương theo từng đơn vị. Cho hiện bản thống kê lên màn hình, sau đó có thể in ra máy nếu muốn. Thống kê những người trong vòng 2 năm tới sẽ về hưu theo từng đơn vị. Kết quả thống kê có thể hiện lên màn hình và in (như mục 3.2)/ Ngôn ngữ thực hiện: turbo C PHẦN II: THIẾT KẾ CHỨC NĂNG Sau khi nghiên kỹ đề tài, em đã vạch ra được một phương hướng thiết kế chương trình như sau: Quản lý nhân sự Thêm, Sửa ,Xóa, Nhân Sự Sắp xếp Thống Kê Ghi File In ra máy Một số giao diện của chương trình: PHẦN III: THIẾT KẾ DỮ LIỆU Dữ liệu của chương trình: Chương trình có sử dụng các loại dữ liệu là : Cấu trúc. Tệp tin nhị phân. Danh sách liên kết. Dữ liệu về nhân sự: struct NhanSu { char sHoTen[25],sDonVi[25],sHocVi[15]; int iNamSinh,iNamLenLuong; unsigned long iMucLuong; struct NhanSu *next; //con trỏ chứa địa chỉ của phần tử Nhân sự sau. struct NhanSu *prev; //con trỏ chứa địa chỉ của phần tử Nhân sự trước. } ; FILE *f1; f1 = fopen("data","a+b"); Dữ liệu sẽ được lưu vào tệp tin nhị phân có tên là “Data”. Tệp tin có thể được sinh ra khi chạy chương trình lần đầu tiên. Chương trình có 2 cách nhập dữ liêu: Nhập đến đâu ghi vào tệp luôn. Nhập vào danh sách liên kết rồi thao tác trên danh sách liên kết, sau đó ghi vào tệp. Chương trình có sử dụng các thuật toán như: sắp xếp, thao tác với danh sách liên kết cấu trúc các bản ghi. PHẦN IV: THIẾT KẾ MODULE CHƯƠNG TRÌNH Các thư viện cần dùng trong chương trình là: #include #include #include #include #include #include Chương trình được tổ chức thành các hàm: void Menu(); //Thủ tục gọi Menu của chương trình void NhapMoi(); //Thủ tục thực hiện việc nhập mới Nhân Sự void DSNhanSu(); //Thủ tục liệt kê danh sách các Nhan Sự void Sua(); //Thủ tục sửa thông tin Nhân Sự void Sapxep(); //Thủ tục sắp xếp danh sách Nhân Sự theo các trường void ThongKe(); //Thủ tục Thống kê Nhân Sự void main() //Hàm chính của chương trình { int iChon = 0; struct NhanSu objNhanSu; FILE *f1; while(iChon!=8) { clrscr(); Menu(); scanf("%d",&iChon); switch(iChon) { case 1: NhapMoi2(); break; case 2: Sua(); break; case 3: DocDuLieu();break; case 4: DSNhanSu(); break; case 5: Sapxep(); break; case 6: ThongKe(); break; default: break; } } } PHẦN IV: CÀI ĐẶT VÀ HƯỚNG DẪN SỬ DỤNG CHƯƠNG TRÌNH Chương trình gồm file QLNS.C được dịch thành 1 file QLNS.exe duy nhất. Sau khi chạy thì chương trình sẽ tạo ra một file tên là “Data” sẽ chứa dữ liệu về thông tin của Nhân sự. Sử dụng chương trình Chạy file QLNS.exe, giao diện đầu tiên là: Chọn 1: để nhập Danh sách Nhân Sự: Sau khi nhập có thể dùng phím Page Up và Page Down để xem thông tin của Người trước và Người sau. Từ Menu Chọn 2 để sửa thông tin Nhân Sự Chọn 3 để đọc dữ liệu từ file từ đó có thể làm các thao tác như mục 1. Chọn 4 để liệt kê danh sách nhân sự. Chọn 5 để sắp xếp danh sách Nhân sự theo các trường. Chọn 6 để Thống kê. PHẦN V: KẾT LUẬN Đây là chương trình được em thực hiện sau 1 tháng, chương trình đã đáp ứng được các chức năng cơ bản của 1 chương trình Quản lý nhân sự. Áp dụng những kiến thức đã học, em đã xây dựng chương trình này, tuy nhiên chương trình vẫn còn một số hạn chế, và sai sót. Chương trình được viết thành các thủ tục tuy nhiên còn nhiều phần bị lặp lại do chưa tối ưu được cấu trúc của chương trình. Phương hướng của sắp tới của em là tối ưu hóa chương trình,phát triển chương trình hoàn hảo hơn. Chương trình được hoàn thành với sự giúp đỡ nhiệt tình của GS.TS.Phạm Văn Ất. Cũng nhân dịp này em xin cảm ơn tới thầy hướng dẫn của mình và các bạn đã giúp đỡ em hoàn thành chương trình. . PHỤ LỤC Mã nguồn của chương trình void Menu()//Menu chinh' cua chuong trinh { printf("\n\t\tMENU\n\n"); printf("\t1. Nhap Nhan Su\n"); printf("\t2. Sua Thong Tin Nhan Su\n"); printf("\t3. Xoa Nhan Su\n"); printf("\t4. Danh Sach Nhan Su\n"); printf("\t5. Sap Xep\n"); printf("\t6. Thong Ke\n"); printf("\t7. Doc Du Lieu\n"); printf("\t8. Thoat\n\n"); printf("\t\tChon: "); } void NhapMoi() { char c = 'c',cSua; int n; struct NhanSu *NStmp; struct NhanSu *Q; char sHoTentmp[25],sDonVitmp[25],sHocVitmp[15]; struct NhanSu *NStmp2; struct NhanSu *NStmp3; struct NhanSu *NStmp4; struct NhanSu *NStmp5; struct NhanSu *first; struct NhanSu *last; struct NhanSu *tg1,*tg2; struct NhanSu objNhanSu; char c1; char ch; FILE *f1; int i; first = NULL; last = NULL; f1 = fopen("data","a+b"); if(f1==NULL) { printf("\nI/O Error"); exit(1); } i = 0; clrscr(); n = 0; do { printf("\n\t\t\tNhap moi Nhan Su"); NStmp = (struct NhanSu *)malloc(sizeof(struct NhanSu)); fflush(stdin); printf("\n\n\t Nhap thong tin nguoi thu %d:\n\n",i + 1); fflush(stdin); printf("\t%-10s","Ho va Ten:");gets(NStmp->sHoTen); printf("\t%-10s","Nam Sinh:"); scanf("%d",&NStmp->iNamSinh); fflush(stdin); printf("\t%-10s","Don Vi:"); gets(NStmp->sDonVi); printf("\t%-10s","Nam len luong:"); scanf("%d",&NStmp->iNamLenLuong); fflush(stdin); printf("\t%-10s","Hoc Vi:");gets(NStmp->sHocVi); printf("\t%-10s","Muc Luong:"); scanf("%lu",&NStmp->iMucLuong); n++; if(first == NULL) { first = last = NStmp; first->prev = NULL ; } else { last->next = NStmp; NStmp->prev = last; // last = NStmp; NStmp->next = NULL; last = NStmp; } i++; printf("\t\t\tBan co tiep tuc nhap nua khong (c/k): "); fflush(stdin); scanf("%c",&c); clrscr(); } while((c == 'c')||(c == 'C')); printf("\n\t\t\tXem thong tin nguoi truoc Pg Up "); printf("\n\t\t\tXem thong tin nguoi sau Pg Dn "); last->next = NULL; NStmp2 = last; NStmp3 = first; getch(); do { c1 = getch(); switch(c1) { case 73:if(NStmp2!=NULL) { clrscr(); tg1 = NStmp2; NStmp2 = NStmp2->prev; if(NStmp2==NULL)NStmp2 = tg1; printf("\n\t\tHo va Ten:%s",NStmp2->sHoTen); printf("\n\t\tNam Sinh:%d",NStmp2->iNamSinh); printf("\n\t\tDon Vi:%s",NStmp2->sDonVi); printf("\n\t\tNam Len Luong:%d",NStmp2->iNamLenLuong); printf("\n\t\tHoc Vi:%s",NStmp2->sHocVi); printf("\n\t\tMuc Luong:%lu",NStmp2->iMucLuong); printf("\n\n\t\tSua thong tin(bam phim 's')"); printf("\n\n\t\tChen 1 ban ghi vao sau ban ghi nay(bam phim 'c')"); printf("\n\n\t\tXoa ban ghi nay(bam phim 'x')"); printf("\n\n\t\tTro lai Menu chinh(bam phim 't')"); } ;break; case 81:if(NStmp2!=NULL) { clrscr(); tg2 = NStmp2; NStmp2 = NStmp2->next; if(NStmp2==NULL)NStmp2 = tg2; printf("\n\t\tHo va Ten:%s",NStmp2->sHoTen); printf("\n\t\tNam Sinh:%d",NStmp2->iNamSinh); printf("\n\t\tDon Vi:%s",NStmp2->sDonVi); printf("\n\t\tNam Len Luong:%d",NStmp2->iNamLenLuong); printf("\n\t\tHoc Vi:%s",NStmp2->sHocVi); printf("\n\t\tMuc Luong:%lu",NStmp2->iMucLuong); printf("\n\n\t\tSua thong tin(bam phim 's')"); printf("\n\n\t\tChen 1 ban ghi vao sau ban ghi nay(bam phim 'c')"); printf("\n\n\t\tXoa ban ghi nay(bam phim 'x')"); printf("\n\n\t\tTro lai Menu chinh(bam phim 't')"); } ;break; case 115: fflush(stdin); printf("\n\t%-10s","Ho va Ten:");gets(NStmp2->sHoTen); printf("\t%-10s","Nam Sinh:"); scanf("%d",&NStmp2->iNamSinh); fflush(stdin); printf("\t%-10s","Don Vi:"); gets(NStmp2->sDonVi); printf("\t%-10s","Nam len luong:"); scanf("%d",&NStmp2->iNamLenLuong); fflush(stdin); printf("\t%-10s","Hoc Vi:");gets(NStmp2->sHocVi); printf("\t%-10s","Muc Luong:"); scanf("%lu",&NStmp2->iMucLuong); printf("Da sua xong ! Bam Pg up Pg Dn de xem tiep"); break; case 99: Q = calloc(1,sizeof(struct NhanSu)); fflush(stdin); printf("\n\n\t%-10s","Ho va Ten:");gets(sHoTentmp);strcpy(Q->sHoTen,sHoTentmp); printf("\n\t%-10s","Nam Sinh:"); scanf("%d",&Q->iNamSinh); fflush(stdin); printf("\n\t%-10s","Don Vi:"); gets(sDonVitmp);strcpy(Q->sDonVi,sDonVitmp); printf("\n\t%-10s","Nam len luong:"); scanf("%d",&Q->iNamLenLuong); fflush(stdin); printf("\n\t%-10s","Hoc Vi:"); gets(sHocVitmp);strcpy(Q->sHocVi,sHocVitmp); printf("\n\t%-10s","Muc Luong:"); scanf("%lu",&Q->iMucLuong); NStmp4 = NStmp2->next; if(NStmp4==NULL) { last->next = Q; Q->prev = last; // last = NStmp; Q->next = NULL; last = Q; clrscr(); printf("Da chen vao cuoi danh sach!"); } else { Q->next = NStmp2->next; NStmp2->next = Q; Q->prev = NStmp4->prev; NStmp4->prev = Q; printf("Da chen them ban ghi moi ! Bam Pg up Pg Dn de xem tiep"); } break; case 120: NStmp4 = NStmp2->next; NStmp5 = NStmp2->prev; if(NStmp4==NULL) { NStmp2 = NStmp5; NStmp2->next = NULL; } else { NStmp5->next = NStmp4; NStmp4->prev = NStmp5; } clrscr(); printf("\n\n\tBan ghi Da xoa,Bam Pg Up Pg Dn de xem tiep"); break; } }while (c1!=116); clrscr(); fflush(stdin); printf("\n\t\tGhi len File(c/k)"); scanf("%c",&c); if(c=='c') { do { fwrite(NStmp3,sizeof(struct NhanSu),1,f1); NStmp3 = NStmp3->next; }while(NStmp3!=NULL) ; printf("bam phim 't' de tro ve Menu"); } clrscr(); free(tg1); free(tg2); free(NStmp); free(NStmp2); free(NStmp3); free(first); free(last); fclose(f1); } void load() { struct NhanSu objNhanSu; FILE *f1; int i = 0; f1 = fopen("data","rb"); if(f1==NULL) { printf("\nI/O Error"); exit(1); } printf("\n\t\t\tDanh sach Nhan Su\n\n"); printf("%-4s%-20s%-10s%-15s%-10s%-10s%-10s\n","STT","Ho Ten","Nam Sinh","Don Vi","Nam LL","Hoc Vi","Muc Luong"); printf("%-4s%-20s%-10s%-15s%-10s%-10s%-10s\n","---","------","--------","------","------","------","---------"); while(fread(&objNhanSu,sizeof(objNhanSu),1,f1)==1) { printf("%-4d%-20s%-10d%-15s%-10d%-10s%-10lu\n",i+1,objNhanSu.sHoTen,objNhanSu.iNamSinh,objNhanSu.sDonVi,objNhanSu.iNamLenLuong,objNhanSu.sHocVi,objNhanSu.iMucLuong); i++; } fclose(f1); } void DSNhanSu() { clrscr(); load(); printf("\n\n\nBam nut bat ky de thoat !"); getch(); } void Sua() { char sHoTen[25]; int found = 0; struct NhanSu objNhanSu; FILE *f1; int i = 0; int iChon2; f1 = fopen("data","r+b"); if(f1==NULL) { printf("\nI/O Error"); exit(1); } clrscr(); fflush(stdin); printf("\n\n\n\tCho biet ten Nguoi can sua:"); gets(sHoTen); while(fread(&objNhanSu,sizeof(objNhanSu),1,f1)==1) { if(stricmp(objNhanSu.sHoTen,sHoTen)==0) { printf("%-4s%-20s%-10s%-15s%-10s%-10s%-10s\n","STT","Ho Ten","Nam Sinh","Don Vi","Nam LL","Hoc Vi","Muc Luong"); printf("%-4s%-20s%-10s%-15s%-10s%-10s%-10s\n","---","------","--------","------","------","------","---------"); printf("%-4d%-20s%-10d%-15s%-10d%-10s%-10lu\n",i+1,objNhanSu.sHoTen,objNhanSu.iNamSinh,objNhanSu.sDonVi,objNhanSu.iNamLenLuong,objNhanSu.sHocVi,objNhanSu.iMucLuong); found = 1; printf("\tChon :\n "); printf("\t\t1. De Sua Ho Ten\n"); printf("\t\t2. De Sua Nam Sinh\n"); printf("\t\t3. De Sua Don Vi\n"); printf("\t\t4. De Sua Nam Len Luong\n"); printf("\t\t5. De Sua Hoc Vi\n"); printf("\t\t6. De Sua Muc Luong\n"); printf("\t\t7. Thoat\n"); printf("\tChon : "); scanf("%d",&iChon2); switch(iChon2) { case 1: fflush(stdin);printf("Nhap Ho Ten Moi:");gets(objNhanSu.sHoTen); fseek(f1,sizeof(objNhanSu)*i,0); fwrite(&objNhanSu,sizeof(objNhanSu),1,f1); fclose(f1); break; case 2: fflush(stdin);printf("Nhap Nam Sinh Moi:");scanf("%d",&objNhanSu.iNamSinh); fseek(f1,sizeof(objNhanSu)*i,0); fwrite(&objNhanSu,sizeof(objNhanSu),1,f1); fclose(f1); break; case 3: fflush(stdin);printf("Nhap Don Vi Moi:");gets(objNhanSu.sDonVi); fseek(f1,sizeof(objNhanSu)*i,0); fwrite(&objNhanSu,sizeof(objNhanSu),1,f1); fclose(f1); break; case 4: fflush(stdin);printf("Nhap Nam Len Luon Moi:");scanf("%d",&objNhanSu.iNamLenLuong); fseek(f1,sizeof(objNhanSu)*i,0); fwrite(&objNhanSu,sizeof(objNhanSu),1,f1); fclose(f1); break; case 5: fflush(stdin);printf("Nhap Hoc Vi Moi:");gets(objNhanSu.sHocVi); fseek(f1,sizeof(objNhanSu)*i,0); fwrite(&objNhanSu,sizeof(objNhanSu),1,f1); fclose(f1); break; case 6: fflush(stdin);printf("Nhap Muc Luong Moi:");scanf("%lu",&objNhanSu.iMucLuong); fseek(f1,sizeof(objNhanSu)*i,0); fwrite(&objNhanSu,sizeof(objNhanSu),1,f1); fclose(f1); break; default: ;break; } break; } i++; } if(found==0) { printf("Khong tim thay !"); getch(); }; } void Sapxep() { int iChon3; char cChon; struct NhanSu objNhanSu; FILE *f1; struct NhanSu *ptr; int i,x,j,k,m,n,p; struct NhanSu tgNhanSu; clrscr(); printf("\n\n\tSap xep theo:\n"); printf("\t\t1.Nam Sinh\n"); printf("\t\t2.Nam Len Luong\n"); printf("\t\t3.Muc Luong\n"); printf("\tChon :");scanf("%d",&iChon3); i = 0; f1 = fopen("data","r+b"); if(f1==NULL) { printf("\nI/O Error"); exit(1); } while(fread(&objNhanSu,sizeof(objNhanSu),1,f1)==1) { i++; } rewind(f1); ptr = (struct NhanSu *)calloc(i,sizeof(struct NhanSu));//cap phat bo nho' x = 0; while(fread(&objNhanSu,sizeof(objNhanSu),1,f1)==1) { strcpy((ptr+x)->sHoTen,objNhanSu.sHoTen); (ptr+x)->iNamSinh = objNhanSu.iNamSinh; strcpy((ptr+x)->sDonVi,objNhanSu.sDonVi); (ptr+x)->iNamLenLuong = objNhanSu.iNamLenLuong; strcpy((ptr+x)->sHocVi,objNhanSu.sHocVi); (ptr+x)->iMucLuong = objNhanSu.iMucLuong; x++; } switch(iChon3) { case 1: for(j=0;j<i-1;j++) { for(k = j+1;k<i;k++) { if((ptr+j)->iNamSinh>(ptr+k)->iNamSinh) { tgNhanSu.iNamSinh = (ptr+j)->iNamSinh; (ptr+j)->iNamSinh = (ptr+k)->iNamSinh; (ptr+k)->iNamSinh = tgNhanSu.iNamSinh; tgNhanSu.iNamLenLuong = (ptr+j)->iNamLenLuong; (ptr+j)->iNamLenLuong = (ptr+k)->iNamLenLuong; (ptr+k)->iNamLenLuong = tgNhanSu.iNamLenLuong; tgNhanSu.iMucLuong = (ptr+j)->iMucLuong; (ptr+j)->iMucLuong = (ptr+k)->iMucLuong; (ptr+k)->iMucLuong = tgNhanSu.iMucLuong; strcpy(tgNhanSu.sHoTen,(ptr+j)->sHoTen); strcpy((ptr+j)->sHoTen,(ptr+k)->sHoTen); strcpy((ptr+k)->sHoTen,tgNhanSu.sHoTen); strcpy(tgNhanSu.sDonVi,(ptr+j)->sDonVi); strcpy((ptr+j)->sDonVi,(ptr+k)->sDonVi); strcpy((ptr+k)->sDonVi,tgNhanSu.sDonVi); strcpy(tgNhanSu.sHocVi,(ptr+j)->sHocVi); strcpy((ptr+j)->sHocVi,(ptr+k)->sHocVi); strcpy((ptr+k)->sHocVi,tgNhanSu.sHocVi); } } }; n = i; printf("%-4s%-20s%-10s%-15s%-10s%-10s%-10s\n","STT","Ho Ten","Nam Sinh","Don Vi","Nam LL","Hoc Vi","Muc Luong"); printf("%-4s%-20s%-10s%-15s%-10s%-10s%-10s\n","---","------","--------","------","------","------","---------"); for(i = 0;i < n;i++) { printf("%-4d%-20s%-10d%-15s%-10d%-10s%-10lu\n",i+1,(ptr+i)->sHoTen,(ptr+i)->iNamSinh,(ptr+i)->sDonVi,(ptr+i)->iNamLenLuong,(ptr+i)->sHocVi,(ptr+i)->iMucLuong); } printf("\n\nGhi Vao File(c/k) :"); fflush(stdin); scanf("%c",&cChon); if(cChon =='c'||cChon == 'C') { rewind(f1); for(i=0;i<n;i++) { fwrite((ptr+i),sizeof(objNhanSu),1,f1); } printf("\n\n\n\tDa ghi xong !"); getch(); } fclose(f1); free(ptr); break; case 2: for(j=0;j<i-1;j++) { for(k = j+1;k<i;k++) { if((ptr+j)->iNamLenLuong>(ptr+k)->iNamLenLuong) { tgNhanSu.iNamSinh = (ptr+j)->iNamSinh; (ptr+j)->iNamSinh = (ptr+k)->iNamSinh; (ptr+k)->iNamSinh = tgNhanSu.iNamSinh; tgNhanSu.iNamLenLuong = (ptr+j)->iNamLenLuong; (ptr+j)->iNamLenLuong = (ptr+k)->iNamLenLuong; (ptr+k)->iNamLenLuong = tgNhanSu.iNamLenLuong; tgNhanSu.iMucLuong = (ptr+j)->iMucLuong; (ptr+j)->iMucLuong = (ptr+k)->iMucLuong; (ptr+k)->iMucLuong = tgNhanSu.iMucLuong; strcpy(tgNhanSu.sHoTen,(ptr+j)->sHoTen); strcpy((ptr+j)->sHoTen,(ptr+k)->sHoTen); strcpy((ptr+k)->sHoTen,tgNhanSu.sHoTen); strcpy(tgNhanSu.sDonVi,(ptr+j)->sDonVi); strcpy((ptr+j)->sDonVi,(ptr+k)->sDonVi); strcpy((ptr+k)->sDonVi,tgNhanSu.sDonVi); strcpy(tgNhanSu.sHocVi,(ptr+j)->sHocVi); strcpy((ptr+j)->sHocVi,(ptr+k)->sHocVi); strcpy((ptr+k)->sHocVi,tgNhanSu.sHocVi); } } }; m = i; printf("%-4s%-20s%-10s%-15s%-10s%-10s%-10s\n","STT","Ho Ten","Nam Sinh","Don Vi","Nam LL","Hoc Vi","Muc Luong"); printf("%-4s%-20s%-10s%-15s%-10s%-10s%-10s\n","---","------","--------","------","------","------","---------"); for(i = 0;i < m;i++) { printf("%-4d%-20s%-10d%-15s%-10d%-10s%-10lu\n",i+1,(ptr+i)->sHoTen,(ptr+i)->iNamSinh,(ptr+i)->sDonVi,(ptr+i)->iNamLenLuong,(ptr+i)->sHocVi,(ptr+i)->iMucLuong); } printf("\n\nGhi Vao File(c/k) :"); fflush(stdin); scanf("%c",&cChon); if(cChon =='c'||cChon == 'C') { rewind(f1); for(i=0;i<m;i++) { fwrite((ptr+i),sizeof(objNhanSu),1,f1); } printf("\n\n\n\tDa ghi xong !"); getch(); } fclose(f1); free(ptr); break; case 3: for(j=0;j<i-1;j++) { for(k = j+1;k<i;k++) { if((ptr+j)->iMucLuong>(ptr+k)->iMucLuong) { tgNhanSu.iNamSinh = (ptr+j)->iNamSinh; (ptr+j)->iNamSinh = (ptr+k)->iNamSinh; (ptr+k)->iNamSinh = tgNhanSu.iNamSinh; tgNhanSu.iNamLenLuong = (ptr+j)->iNamLenLuong; (ptr+j)->iNamLenLuong = (ptr+k)->iNamLenLuong; (ptr+k)->iNamLenLuong = tgNhanSu.iNamLenLuong; tgNhanSu.iMucLuong = (ptr+j)->iMucLuong; (ptr+j)->iMucLuong = (ptr+k)->iMucLuong; (ptr+k)->iMucLuong = tgNhanSu.iMucLuong; strcpy(tgNhanSu.sHoTen,(ptr+j)->sHoTen); strcpy((ptr+j)->sHoTen,(ptr+k)->sHoTen); strcpy((ptr+k)->sHoTen,tgNhanSu.sHoTen); strcpy(tgNhanSu.sDonVi,(ptr+j)->sDonVi); strcpy((ptr+j)->sDonVi,(ptr+k)->sDonVi); strcpy((ptr+k)->sDonVi,tgNhanSu.sDonVi); strcpy(tgNhanSu.sHocVi,(ptr+j)->sHocVi); strcpy((ptr+j)->sHocVi,(ptr+k)->sHocVi); strcpy((ptr+k)->sHocVi,tgNhanSu.sHocVi); } } }; p = i; printf("%-4s%-20s%-10s%-15s%-10s%-10s%-10s\n","STT","Ho Ten","Nam Sinh","Don Vi","Nam LL","Hoc Vi","Muc Luong"); printf("%-4s%-20s%-10s%-15s%-10s%-10s%-10s\n","---","------","--------","------","------","------","---------"); for(i = 0;i < p;i++) { printf("%-4d%-20s%-10d%-15s%-10d%-10s%-10lu\n",i+1,(ptr+i)->sHoTen,(ptr+i)->iNamSinh,(ptr+i)->sDonVi,(ptr+i)->iNamLenLuong,(ptr+i)->sHocVi,(ptr+i)->iMucLuong); } printf("\n\nGhi Vao File(c/k) :"); fflush(stdin); scanf("%c",&cChon); if(cChon =='c'||cChon == 'C') { rewind(f1); for(i=0;i<p;i++) { fwrite((ptr+i),sizeof(objNhanSu),1,f1); } printf("\n\n\n\tDa ghi xong !"); getch(); } free(ptr); fclose(f1); break; default:break; } } void ThongKe() { int iChon3; char DonVi[25]; //lay ngay thang hien tai FILE *f1; struct NhanSu objNhanSu; int count = 0,found = 0; struct date d; getdate(&d); clrscr(); f1 = fopen("data","rb"); if(f1==NULL) { printf("\nI/O Error"); exit(1); } printf("\n\n\tThong Ke Theo:\n"); printf("\t\t1.Danh Sach Nhung Nguoi Du Thoi Han Len Luong Theo Tung Don Vi.\n"); printf("\t\t2.Nhung Nguoi Trong Vong 2 Nam Toi Se Ve Huu Theo Tung Don Vi.\n"); printf("\tChon :");scanf("%d",&iChon3); switch(iChon3) { case 1: printf("\n\n\t\tNhap Don Vi: ");fflush(stdin);gets(DonVi); printf("%-4s%-20s%-10s%-15s%-10s%-10s%-10s\n","STT","Ho Ten","Nam Sinh","Don Vi","Nam LL","Hoc Vi","Muc Luong"); printf("%-4s%-20s%-10s%-15s%-10s%-10s%-10s\n","---","------","--------","------","------","------","---------"); while(fread(&objNhanSu,sizeof(objNhanSu),1,f1)==1) { if(stricmp(objNhanSu.sDonVi,DonVi)==0&&(d.da_year-objNhanSu.iNamLenLuong)==3) { printf("%-4d%-20s%-10d%-15s%-10d%-10s%-10lu\n",count+1,objNhanSu.sHoTen,objNhanSu.iNamSinh,objNhanSu.sDonVi,objNhanSu.iNamLenLuong,objNhanSu.sHocVi,objNhanSu.iMucLuong); count++; found = 1; } } if(found==1)getch(); if(found==0) { printf("Khong tim thay !"); getch(); }; fclose(f1); break; case 2: printf("\n\n\t\tNhap Don Vi: ");fflush(stdin);gets(DonVi); printf("%-4s%-20s%-10s%-15s%-10s%-10s%-10s\n","STT","Ho Ten","Nam Sinh","Don Vi","Nam LL","Hoc Vi","Muc Luong"); printf("%-4s%-20s%-10s%-15s%-10s%-10s%-10s\n","---","------","--------","------","------","------","---------"); while(fread(&objNhanSu,sizeof(objNhanSu),1,f1)==1) { if(stricmp(objNhanSu.sDonVi,DonVi)==0&&(d.da_year-objNhanSu.iNamSinh)>=58&&(d.da_year-objNhanSu.iNamSinh)<=60) { printf("%-4d%-20s%-10d%-15s%-10d%-10s%-10lu\n",count+1,objNhanSu.sHoTen,objNhanSu.iNamSinh,objNhanSu.sDonVi,objNhanSu.iNamLenLuong,objNhanSu.sHocVi,objNhanSu.iMucLuong); count++; found = 1; } } if(found==1)getch(); if(found==0) { printf("Khong tim thay !"); getch(); }; fclose(f1); break; default:break; } } void DocDuLieu() { int iChon3; char cChon; char c1; char c; struct NhanSu *NStmp; struct NhanSu *Q; char sHoTentmp[25],sDonVitmp[25],sHocVitmp[15]; struct NhanSu *NStmp2; struct NhanSu *NStmp3; struct NhanSu *NStmp4; struct NhanSu *NStmp5; struct NhanSu *first; struct NhanSu *last; struct NhanSu *tg1,*tg2; struct NhanSu objNhanSu; FILE *f1; int i,x,j,k,m,n,p; struct NhanSu tgNhanSu; clrscr(); first = NULL; last = NULL; i = 0; f1 = fopen("data","rb"); if(f1==NULL) { printf("\nI/O Error"); exit(1); } while(fread(&objNhanSu,sizeof(objNhanSu),1,f1)==1) { i++; } rewind(f1); x = 0; while(fread(&objNhanSu,sizeof(objNhanSu),1,f1)==1) { NStmp = (struct NhanSu *)malloc(sizeof(struct NhanSu)); strcpy(NStmp->sHoTen,objNhanSu.sHoTen); NStmp->iNamSinh = objNhanSu.iNamSinh; strcpy(NStmp->sDonVi,objNhanSu.sDonVi); NStmp->iNamLenLuong = objNhanSu.iNamLenLuong; strcpy(NStmp->sHocVi,objNhanSu.sHocVi); NStmp->iMucLuong = objNhanSu.iMucLuong; if(first == NULL) { first = last = NStmp; first->prev = NULL ; } else { last->next = NStmp; NStmp->prev = last; NStmp->next = NULL; last = NStmp; } x++; } fclose(f1); printf("\n\t\t\tXem thong tin nguoi truoc Pg Up "); printf("\n\t\t\tXem thong tin nguoi sau Pg Dn "); last->next = NULL; NStmp2 = last; NStmp3 = first; if(NStmp2->next!=NULL) printf("\nKO NULL"); else printf("null"); if(NStmp2->prev!=NULL) printf("\nKO NULL"); else printf("null"); getch(); do { c1 = getch(); switch(c1) { case 73:if(NStmp2!=NULL) { clrscr(); tg1 = NStmp2; NStmp2 = NStmp2->prev; if(NStmp2==NULL)NStmp2 = tg1; printf("\n\t\tHo va Ten:%s",NStmp2->sHoTen); printf("\n\t\tNam Sinh:%d",NStmp2->iNamSinh); printf("\n\t\tDon Vi:%s",NStmp2->sDonVi); printf("\n\t\tNam Len Luong:%d",NStmp2->iNamLenLuong); printf("\n\t\tHoc Vi:%s",NStmp2->sHocVi); printf("\n\t\tMuc Luong:%lu",NStmp2->iMucLuong); printf("\n\n\t\tSua thong tin(bam phim 's')"); printf("\n\n\t\tChen 1 ban ghi vao sau ban ghi nay(bam phim 'c')"); printf("\n\n\t\tXoa ban ghi nay(bam phim 'x')"); printf("\n\n\t\tTro lai Menu chinh(bam phim 't')"); } ;break; case 81:if(NStmp2!=NULL) { clrscr(); tg2 = NStmp2; NStmp2 = NStmp2->next; if(NStmp2==NULL)NStmp2 = tg2; printf("\n\t\tHo va Ten:%s",NStmp2->sHoTen); printf("\n\t\tNam Sinh:%d",NStmp2->iNamSinh); printf("\n\t\tDon Vi:%s",NStmp2->sDonVi); printf("\n\t\tNam Len Luong:%d",NStmp2->iNamLenLuong); printf("\n\t\tHoc Vi:%s",NStmp2->sHocVi); printf("\n\t\tMuc Luong:%lu",NStmp2->iMucLuong); printf("\n\n\t\tSua thong tin(bam phim 's')"); printf("\n\n\t\tChen 1 ban ghi vao sau ban ghi nay(bam phim 'c')"); printf("\n\n\t\tXoa ban ghi nay(bam phim 'x')"); printf("\n\n\t\tTro lai Menu chinh(bam phim 't')"); } ;break; case 115: fflush(stdin); printf("\n\t%-10s","Ho va Ten:");gets(NStmp2->sHoTen); printf("\t%-10s","Nam Sinh:"); scanf("%d",&NStmp2->iNamSinh); fflush(stdin); printf("\t%-10s","Don Vi:"); gets(NStmp2->sDonVi); printf("\t%-10s","Nam len luong:"); scanf("%d",&NStmp2->iNamLenLuong); fflush(stdin); printf("\t%-10s","Hoc Vi:");gets(NStmp2->sHocVi); printf("\t%-10s","Muc Luong:"); scanf("%lu",&NStmp2->iMucLuong); printf("Da sua xong ! Bam Pg up Pg Dn de xem tiep"); break; case 99: Q = calloc(1,sizeof(struct NhanSu)); fflush(stdin); printf("\n\n\t%-10s","Ho va Ten:");gets(sHoTentmp);strcpy(Q->sHoTen,sHoTentmp); printf("\n\t%-10s","Nam Sinh:"); scanf("%d",&Q->iNamSinh); fflush(stdin); printf("\n\t%-10s","Don Vi:"); gets(sDonVitmp);strcpy(Q->sDonVi,sDonVitmp); printf("\n\t%-10s","Nam len luong:"); scanf("%d",&Q->

Các file đính kèm theo tài liệu này:

  • doc77245.DOC