/* ----------------------------------------------------------------------------- FUNCTION NAME: void Record_Sort(CLI *, database *, fstream *, char *, char *) PURPOSE: loads classes into vector, and if needs to redo the output file RETURNS: void NOTES: ----------------------------------------------------------------------------- */ void Record_Sort(Command_line_Record * GivenChars, fstream * databasefile, char *Filename, char *Reportname) { Open_File(Filename, databasefile); //all functions require that this file is opened. vector<database> Records(1); //create vector for database entries, and make at least one empty one. int n=-1, i = 0; // n = for do loop only i = number of records that were opened. bool change_file = false; //T/F check to determin if vector has changed do{ // load file into class vector. i++; Records.resize(i); n++; *databasefile >> Records[n]; }while ((*databasefile).eof() == 0); //run until end of file VERBOSE(3) << "loaded file\n"; databasefile->close(); if (GivenChars->add_acount_true() == 1) // check to see if adding account { Add_Account(GivenChars, Records, &i, &n); change_file = true; } else if (GivenChars->Arg_Given[Command_line_Record::reportfile] == true) { Print_Report(Reportname, Records, &i); } else if (GivenChars->transfer() == 1) { Funds_Transfer_Add(Records, GivenChars); change_file = true; } else if (GivenChars->Arg_Given[Command_line_Record::deleaccnt] == true) { n = Delete_Account(Records, GivenChars, &i); if (n>=0) { Records.erase(Records.begin()+n); change_file = true; VERBOSE(3) << "Account Deleted.\n"; } } else { for (n=0; n<i; n++) { database *rec = &Records[n]; //create pointer to current vector location if ((!strncmp(GivenChars->Get_Account(), rec->Get_Account(), 5)) && (!strncmp(GivenChars->Get_PassWd(), rec->Get_PassWd(), 6))) //check that account number and password match { CLI_Sort(GivenChars, rec, &change_file); } } } if (change_file == true) //if a record was chaged, rewrite the output file { databasefile->open(Filename, ios::out | ios::trunc); for (n=0;n<i;n++) { *databasefile << Records[n]; } databasefile->close(); } }
int main(int argc, char *argv[]) { struct sockaddr_in socket_addr_connect; int connect_fd; unsigned int size_sockaddr; int Search_status = 1; int Tcp_server_status; int Read_status; // int Op_cre_DB_status; char Result_str[300]; char recv_buf[100]; char command_buf[100]; char account_buf[100]; char password_buf[100]; int Check_Result; int i,j; Open_Login_Database(); Open_history_Database(); Tcp_server_status = Init_TCP_Server();//init the tcp server if(Tcp_server_status == 1) { perror("create socket failed"); exit(-1); } else if(Tcp_server_status == 2) { perror("bind failed"); exit(-1); } else if(Tcp_server_status == 3) { perror("listen failed"); exit(-1); } else if(Tcp_server_status == 0) { printf("start listen!\n"); } while(1) { size_sockaddr = sizeof(socket_addr_connect); /*pick up the pass connect 3th*/ connect_fd = accept(listen_fd, (struct sockaddr *)&socket_addr_connect, &size_sockaddr); printf("%s Connected,Port:%d\n", inet_ntoa(socket_addr_connect.sin_addr), ntohs(socket_addr_connect.sin_port)); while(1) { memset(command_buf,'\0',sizeof(command_buf)); Read_status = recv(connect_fd,command_buf,100,0); if(Read_status < 0) { perror("recive"); exit(-1); } else if(Read_status == 0) { printf("client disconnect!\n"); break; } /*register a new account */ if(strcmp(command_buf,"register_account") == 0) { printf("register a new account!\n"); while(1) { memset(recv_buf,'\0',sizeof(recv_buf)); Read_status = recv(connect_fd,recv_buf,100,0); if(Read_status < 0) { perror("recive"); exit(-1); } else if(Read_status == 0) { // printf("client disconnect!\n"); break; } i = 0; j = 0; while(1) { while(recv_buf[i] != ',') { account_buf[i] = recv_buf[i]; i++; } printf("new account =%s\n",account_buf); i++; while(recv_buf[i] != '\0') { password_buf[j] = recv_buf[i]; i++; j++; } printf("new password=%s\n",password_buf); break; } memset(recv_buf,'\0',sizeof(recv_buf)); Check_Result = -1; Check_Result = Check_Account_Passwd(account_buf,password_buf); printf("register Check Result=%d",Check_Result); if((Check_Result != 0)&&(Check_Result != 1)&&(Check_Result != -1)) { Check_Result = -1; Add_Account(account_buf,password_buf); send(connect_fd,"account_created",sizeof("account_created"),0); memset(account_buf,'\0',sizeof(account_buf)); memset(password_buf,'\0',sizeof(password_buf)); break; } else { Check_Result = -1; send(connect_fd,"account_exsit",sizeof("account_exsit"),0); memset(account_buf,'\0',sizeof(account_buf)); memset(password_buf,'\0',sizeof(password_buf)); break; } } } /*login*/ if(strcmp(command_buf,"login_account") == 0) { printf("start login\n"); memset(recv_buf,'\0',sizeof(recv_buf)); /*read a str of login_account */ Read_status = recv(connect_fd,recv_buf,100,0); if(Read_status < 0) { perror("recive"); exit(-1); } else if(Read_status == 0) { // printf("client disconnect!\n"); break; } printf("client_start_login:%s\n",recv_buf); i = 0; j = 0; while(1) { printf("start assiant account\n"); while(recv_buf[i] != ',') { account_buf[i] = recv_buf[i]; i++; } printf("login_account_buf=%s\n",account_buf); i++; while(recv_buf[i] != '\0') { password_buf[j] = recv_buf[i]; i++; j++; } printf("login_password_buf=%s\n",password_buf); break; } memset(recv_buf,'\0',sizeof(recv_buf)); Check_Result = -1; Check_Result = Check_Account_Passwd(account_buf,password_buf); printf("Check_Result=%d\n",Check_Result); if(Check_Result == 0) { Check_Result = -1; send(connect_fd,"account_pass",sizeof("account_pass"),0); memset(account_buf,'\0',sizeof(account_buf)); memset(password_buf,'\0',sizeof(password_buf)); } else { Check_Result = -1; send(connect_fd,"account_nopass",sizeof("account_nopass"),0); memset(account_buf,'\0',sizeof(account_buf)); memset(password_buf,'\0',sizeof(password_buf)); } printf("login_end\n"); } if(strcmp(command_buf,"entry_find") == 0) { printf("start find\n"); while(1) { memset(recv_buf,'\0',sizeof(recv_buf)); memset(Result_str,'\0',sizeof(Result_str)); /*read a str named recv_buf from someone connect */ Read_status = recv(connect_fd,recv_buf,100,0); if(Read_status < 0) { perror("recive"); exit(-1); } else if(Read_status == 0) { // printf("client disconnect!\n"); break; } if(strcmp(recv_buf,"exit_find") == 0) { break; } printf("from client:%s\n",recv_buf); /*search out the Result_str by dirc str in recv_buf */ Search_status = Search_Data(recv_buf, Result_str); switch(Search_status) { case -1:printf("Open ./dict.txt failed!\n"); strcpy(Result_str,"Open ./dict.txt failed!"); break; case 0:printf("Not find this word!\n"); strcpy(Result_str,"Not find this word!"); break; case 1:printf("%s: %s\n", recv_buf, Result_str); break; default:break; } /*send the dirc str to client*/ send(connect_fd,Result_str,strlen(Result_str),0); } printf("end find\n"); } } close(connect_fd); } return 0; }
int DB_Init_Model::Add_Term_Account(const wxString& name, double initial_value, const wxString& notes, bool favorite, const wxString& currency_symbol) { return Add_Account(name, Model_Account::TYPE::TERM, initial_value, notes, favorite, currency_symbol); }
int DB_Init_Model::Add_Investment_Account(const wxString& name, double initial_value, const wxString& notes, bool favorite, const wxString& currency_symbol) { return Add_Account(name, Model_Account::TYPE::INVESTMENT, initial_value, notes, favorite, currency_symbol); }