www.gusucode.com > 学生管理系统的一个例子GUI界面的管理matlab源码程序 > 学生管理系统的一个例子GUI界面的管理matlab源码程序/Matlab_database_GUI/matlab_database.m
function varargout = matlab_database(varargin) % MATLAB_DATABASE M-file for matlab_database.fig % MATLAB_DATABASE, by itself, creates a new MATLAB_DATABASE or raises the existing % singleton*. % % H = MATLAB_DATABASE returns the handle to a new MATLAB_DATABASE or the handle to % the existing singleton*. % % MATLAB_DATABASE('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in MATLAB_DATABASE.M with the given input arguments. % % MATLAB_DATABASE('Property','Value',...) creates a new MATLAB_DATABASE or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before matlab_database_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to matlab_database_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help matlab_database % Last Modified by GUIDE v2.5 19-Jan-2000 11:46:38 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @matlab_database_OpeningFcn, ... 'gui_OutputFcn', @matlab_database_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before matlab_database is made visible. function matlab_database_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to matlab_database (see VARARGIN) % Choose default command line output for matlab_database handles.output = hObject; web -browser http://www.ilovematlab.cn/thread-27870-1-1.html % Update handles structure guidata(hObject, handles); % UIWAIT makes matlab_database wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = matlab_database_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; function edit1_Callback(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit1 as text % str2double(get(hObject,'String')) returns contents of edit1 as a double % --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [filename, pathname] = ... uigetfile({'*.mdb';'*.db';'*.*'},'File Selector'); if isequal(filename,0)|isequal(pathname,0) return; else DB_path=[pathname filename]; DB_sourcename='Godman'; LinkDB(DB_path,DB_sourcename,1); %% set(handles.edit1,'string',DB_path) % msgbox('数据库源文件配置完成!','链接完成','help') % end % --- Executes on selection change in listbox1. function listbox1_Callback(hObject, eventdata, handles) % hObject handle to listbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns listbox1 contents as cell array % contents{get(hObject,'Value')} returns selected item from listbox1 % --- Executes during object creation, after setting all properties. function listbox1_CreateFcn(hObject, eventdata, handles) % hObject handle to listbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: listbox controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) dlgTitle='填写学生相关信息'; lineNo=1; prompt={'姓名','学号','学科1','学科2','学科3','学科4','学科5','学科6','学科7','学科8'}; def={'Godman','1101','60','60','60','60','60','60','60','60'}; answer=inputdlg(prompt,dlgTitle,lineNo,def); %% conna=database('Godman','',''); exdata=answer'; colnames={'姓名','学号','学科1','学科2','学科3','学科4','学科5','学科6','学科7','学科8'}; insert(conna,'stu',colnames,exdata) close(conna) %% conna=database('Godman','',''); curs=exec(conna,'select 姓名 from stu'); curs=fetch(curs); data=curs.Data; close(curs) close(conna) set(handles.listbox1,'value',1); set(handles.listbox1,'string',data); set(handles.edit2,'string',length(data)); % --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) String=get(handles.listbox1,'string'); Select=get(handles.listbox1,'value'); Name_Str=cell2mat(String(Select)) SQL=['delete from stu where 姓名=''',Name_Str,''''] %% conna=database('Godman','',''); curs=exec(conna,SQL); %% curs=exec(conna,'select 姓名 from stu'); curs=fetch(curs); data=curs.Data; close(conna) %% set(handles.listbox1,'value',1); set(handles.listbox1,'string',data); set(handles.edit2,'string',length(data)); % --- Executes on button press in pushbutton4. function pushbutton4_Callback(hObject, eventdata, handles) % hObject handle to pushbutton4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) String=get(handles.listbox1,'string'); Select=get(handles.listbox1,'value'); Name_Str=cell2mat(String(Select)); SQL=['select * from stu where 姓名=''',Name_Str,'''']; % conna=database('Godman','',''); curs=exec(conna,SQL); curs=fetch(curs); data=curs.Data; close(curs) close(conna) % dlgTitle='修改学生相关信息'; lineNo=1; prompt={'姓名','学号','学科1','学科2','学科3','学科4','学科5','学科6','学科7','学科8'}; for i=1:length(data) if i~=1 temp=num2str(cell2mat(data(i))); def(i)={temp}; else def(i)=data(i); end end answer=inputdlg(prompt,dlgTitle,lineNo,def); % tab='stu'; colnam=prompt(3:end); newdata=answer(3:end); conna=database('Godman','',''); for i=1:length(colnam) update(conna,'stu',colnam(i),newdata(i),['where 姓名=''',Name_Str,'''']) end close(conna) % --- Executes on button press in pushbutton5. function pushbutton5_Callback(hObject, eventdata, handles) % hObject handle to pushbutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) conna=database('Godman','',''); curs=exec(conna,'select 姓名 from stu'); curs=fetch(curs); data=curs.Data; close(curs) close(conna) set(handles.listbox1,'value',1); set(handles.listbox1,'string',data); % set(handles.edit2,'string',length(data)); function edit2_Callback(hObject, eventdata, handles) % hObject handle to edit2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit2 as text % str2double(get(hObject,'String')) returns contents of edit2 as a double % --- Executes during object creation, after setting all properties. function edit2_CreateFcn(hObject, eventdata, handles) % hObject handle to edit2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end