My Project - Library Management System [Details]

xiaoxiao2021-03-06  23

My Project - Library Management System (LMS) WRITE by Hifan: B033205_WANGQI Wang Qi

Wang Qi

- Tongji University Software College 2003

Written in front -> My project is my own effort, alone finished

Most of them is written by I, and there are many questions and questions about others on csdn.

Or look at MSDN yourself to find a solution ~ This is also a hard thing.

There is a class of code to see someone else is CMYPICTURE display image, which can display PICs in multiple formats.

Source code There are many LMS [main applications] DLL / PICTURE, OtherFunc [DLL]

The code is about 5000 lines ~!

Details begins [Start]

1. Multithreading (initializing connection database has its own splash display picture)

// thread in mysplash init

HWND HWND = this-> getsafehwnd ();

m_pthread = afxbeginthread (myadoconnect, hwnd, thread_priority_normal); // Start Threads THREAD_PRIORITY_HIGHEST

m_pthread-> m_bautode = false; // thread to manually delete

// thread function

Uint myadoconnect (lpvoid pparam)

{

// COM initialization

:: Coinitialize (0);

_ConnectionPtr PConn;

HRESULT HR;

HR = pconn.createInstance (__ uuidof (connection));

En (ac))

{

Try

{

PCONN-> Connectionstring = "provider = oraoledb.racle.1; password = LMS; persist security info = true; user ID = lms; data source = oradb1"; // Settings connection string

PCONN -> ConnectionTimeout = 10; // Setting the timeout time of the connection, optional

PCONN -> CURSORLOCATION = ADUSESERVER; / / Set the position of the cursor, optional

PCONN -> Open (",", ", - 1);

}

Catch (_COM_ERROR & E)

{

CString Strerr;

STRERR.FORMAT ("Error, Connection Database Error ~ / N Error:% S", E.ErrorMessage ());

AfxMessageBox (STRERR);

:: PostMessage ((hwnd) PPARAM, WM_CLOSE, 0, 0);

BPCONN = false;

Return False;

}

}

THEAPP.SETCONN (PCONN);

:: PostMessage ((hwnd) PPARAM, WM_CLOSE, 0, 0);

BPCONN = true;

Return True;

}

2. Fun place ~ (Let the window displayed ~) mylogin.init; mysplash .init

ShowWindow (SW_HIDE);

CRECT RECT;

This-> getClientRect (& Re);

Cpoint centerpt;

Centerpt.x = Rect.width () / 2;

Centerpt.y = Rect.Height () / 2;

CRGN RGN; this-> showwindow (sw_hide);

INT m = getSystemMetrics (SM_CYSIZEFRAME)

For (int i = 0; i

{

Rgn.createRectrgn (Centerpt.x-i, centerpt.y-i, centerpt.x i, centerpt.y i);

SetwindowRgn ((hrgn) rgn.getsafehandle (), true);

ShowWindow;

CenterWindow ();

Rgn.deleteObject ();

}

3. CMYPICTURE is used to process the image (* .jpg, *. Jif, *. Bmp) This class is put in the picture.dll

Avoiding Bitblt can't display * .jpg, *. JIF shortcomings and streechbitblt effect is not good; [Most is to see others]

Class AFX_EXT_CLASS CMYPICTURE

{

PUBLIC:

CMYPICTURE ();

Virtual ~ cmypicture ();

PUBLIC:

Void FreePictureData ();

Bool load (cstring sfilepathname);

Bool Load (uint resourceename, lpcstr resourcety);

Bool loadPictureData (Byte * PBuffer, int nsize);

Bool Saveasbitmap (CString sfilepathname);

Bool Show (CDC * PDC, Cpoint Lefttop, Cpoint Widthheight, Int Magnifyx, Int Magnify);

BOOL Show (CDC * PDC, CRECT DRAWRECT);

Bool ShowbitmapResource (CDC * PDC, Const Int BmpResource, Cpoint Lefttop;

BOOL Updatesizeondc (CDC * PDC);

PUBLIC:

Ipicture * m_ipicture;

Long m_height;

Long M_Weight;

Long m_width;

}

4. CMYSTATIC inherits CSTATIC to display the picture, handle the right click Pop-up dialog box Save the image

// Pop up menu

Void cmyStatic :: OnRButtonUp (uint nflags, cpoint point)

{

{

CMenu Menu, * pmenu

Menu.LoadMenu (idR_Menu1);

Pmenu = menu.getsubmenu (0);

ClientToscreen (& Point);

Pmenu-> TrackPopupnupmenu (TPM_RightButton, Point.x, Point.y, this);

}

CStatic :: OnRButtonup (NFLAGS, POINT);

}

// save Picture

ON_COMMAND (IDC_MENU_SAVE, ONMENUSAVE)

void cmystatic :: onmenusave ()

{

Cstring filepathname;

Cfiledialog DLG (false, null, null, 0,

"JPG Files (* .jpg) | * .jpg | GIF Files (* .jif) | * .gif | BMP files (* .bmp) | * .bmp ||

THIS);

IF (DLG.Domodal () == iDOK)

{

Filepathname = DLG.GetFileName ();

IF (filepathname! = "")

PPIC-> Saveasbitmap (filepathname);

}

5. About ADO connection operation

// Mainly used

_ConnectionPtr PConn;

_Commandptr PCMD;

_RecordSetptr prist;

_VARIANT_T M_VTEMP [10];

// use PRST to traverse

// Execute with PCMD

/ / You can store pictures display images

// Deposit into the database

Try

{

CFILE FILE;

IF (filepathname, cfile :: moderad | cfile :: typebinary))

{

INT nsize = file.getlength ();

BYTE * PBUFFER = New byte [nsize];

IF (file.read (pbuffer, nsize)> 0)

{

// The following code is written in the database data in the PBUFFER.

BYTE * PBUF = PBuffer;

Variant varob;

SafeArray * PSA;

SafeArraybound Rgsabound [1];

PRST-> AddNew ();

IF (PBUF)

{

Rgsabound [0] .llbound = 0;

Rgsabound [0] .CELEMENTS = nsize;

PSA = SafeArrayCreate (VT_UI1, 1, RgSAbound);

For (long i = 0; i <(long) nsize; i )

SafearrayPutelement (PSA, & I, PBUF );

Varblob.vt = vt_Array | VT_UI1;

Varblob.Parray = PSA;

// Before it (PIC) ~

PRST-> Fields-> GetItem ("sno") -> value = m_sno.allocsystring ();

PRST-> getfields () -> GetItem ("PIC") -> Appendchunk (varblob);

// prSt-> Putcollect ("sno", m_sno.allocsystring ());

// PRST-> Putcollect ("PIC", Varblob);

}

PRST-> UPDATE ();

delete [] PBuffer;

PRST-> Close ();

PRST = NULL;

}

File.Close ();

}

}

Catch (_COM_ERROR E)

{

Bret = false;

}

/ / Display the picture to read the picture from the database and display ~

Str.Format ("SELECT * from Picture Where Sno = / '% s /'", m_sno);

SQLSTR = str.allocsystring ();

// first clear.

IF (m_pic.m_ipicture! = null)

m_pic.freePicturedata ();

HR = prSt.createInstance (__ uuidof (recordset);

IF (succeededed (hr)) {

Try

{

PRST-> Open (sqlstr, (idispatch *),

AdoPendynamic, AdlockOptimistic, AdcmdText);

// can only have a record CON_PICTURE_SNO_UNIQUE

IF (! prSt-> myhifaneof)

{

Long nsize = prSt-> getfields () -> GetItem ("PIC") -> actualsize;

IF (nsize> 0)

{

_VARIANT_T VARBLOB;

Varblob = prSt-> getfields () -> GetItem ("PIC") -> getChunk (nsize);

IF (varblob.vt == (vt_array | vt_ui1))

{

IF (Byte * PBuffer = New Byte [nsize 1]) {

Char * PBUF = NULL;

SafearrayAccessData (Varblob.Parray, (void **) & pbuf);

Memcpy (PBuffer, Pbuf, nsize); SafeArrayunAccessData (Varblob.Parray);

m_pic.loadPictureData (PBuffer, nsize);

delete [] PBuffer;

Cguashi :: setPicthenshow ();

}

}

}

}

}

Catch (_COM_ERROR & E)

{

AfxMessageBox (, E.DESCRIPTION ());

}

}

// There are also many places to use affairs ~ Source programs have an introduction

BOOL BRET = FALSE

HR = pconn.createInstance (__ uuidof (connection));

En (ac))

{

PConn = THEAPP.CONN (); // Get PCONN

PCONN-> Begintrans ();

Try

{

// These statements have been initialized in front ~

PCONN-> EXECUTE (_BSTR_T (SQLinertintostudents), 0, Adexecutenorecords;

PCONN-> EXECUTE (_BSTR_T (SQLinertintocard), 0, Adexecutenorecords;

Bret = True;

}

Catch (_COM_ERROR & E) // Get Error

{

AfxMessageBox (E.ErrorMessage ());

}

IF (BRET)

PCONN-> CommitTrans ();

Else

{

PCONN-> rollbacktrans ();

CString Strerr;

STRERR.FORMAT ("% s error ~! / N transaction is about to roll back ~", OracleErRorstr);

AfxMessageBox (STRERR);

EndDialog (101); // End window, this window is modal

Return;

}

}

6. About DLL

I don't want to say more, I wrote two DLLs, one is Picture.dll, the other is OtherFunc.dllPicture.dll: AFX_EXT_CLASS CMYPICTURE Because this class is often used, I put it in the DLL

OtherFunc.dll: DLL of other functions

I will speak in the classroom, so there is nothing to say, I haven't done anything deep in-depth ~

7. Extreme small point

// Hide Window on Taskbar: [Hide on the taskbar] Hide CMYSPLASH

:: setwindowlong (this-> getsafehwnd (), gwl_exstyle, ws_ex_toolwindow;

// TopMost

1. SetwindowPos (& Wndtopmost, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); // in init

2. Void CMAINFRAME :: ONSHOWINDOW (Bool Bshow, uint nstatus) // in show window

{

CframeWnd :: OnshowWindow (BShow, NStatus);

// TopMost

SetwindowPOS (& Wndtopmost, 0,0,0,0, swp_nomove | swp_nosize);

}

// The initiality of the random number can be used to get the random number with rand () ~ [make the program more fun]

SRAND (NULL); // important

// 256 color Toolbar

Although my ICON is ugly, it is painted by my own, and it can be 256 colors ~

// Change the CSTATIC background is transparent

Hbrush CDLGLOGIN :: ONCTLCOLOR (CDC * PDC, CWND * PWND, UINT NCTLCOLOR)

{

Hbrush Hbr = CDIALOG :: ONCTLCOLOR (PDC, PWND, NCTLCOLOR);

// hifan

// for change static bkmode, And Text Color

IF (nctlcolor == ctlcolor_static) // similar CTLColor_BTN ...

{

PDC-> setbkmode (transparent);

PDC-> SetTextColor (RGB (200, 0, 200));

Return (Hbrush) :: getStockObject (null_brush);

}

// end of hifan

Return Hbr;

}

// Modal dialog and non-modular dialog box ~

The teacher told me, I understand some ~ These windows have not completely disappeared after being closed ~

Most of the windows I have built are non-modal ~

// Enable the window child ~ It is necessary ~

CWND * pcwnd = this-> getdlgitem (IDC_ID);

PCWND-> enableWindow;

// I have found that I have to make my return in the EDIT must be "/ r / n" this and C is different ~

CString m_info; // is / r / n; not /n ,/n/r;

m_info.format ("I / R / N is / R / N King / R / N Qi");

This-> Updatedata (false);

// Creation of the multi-page attribute box

CTABCTRL M_TAB;

CPAGE1 PAGE1;

CPAGE2 PAGE2;

INT CDELETE :: OnCreate (lpcreatestruct lpcreatestruct)

{

IF (cdialog :: oncreate (lpcreatestructure) == -1)

Return -1;

M_Tab.create (WS_Visible, CRECT (0, 0, 500, 370), this, IDC_TAB1); M_TAB.INSERTITEM (0, "Delete Student");

m_tab.insertitem (1, "Delete Old Book");

// Page ~

Page1.create (IDD_DIALOG9_PAGE1, THIS);

Page2.create (IDD_DIALOG9_PAGE2, THIS);

Page1.ShowWindow (SW_SHOW);

Page2.ShowWindow (sw_hide);

Return 0;

}

Void Cdlete :: OnSelchangeTab (NmHDR * PNMHDR, LRESULT * PRESULT)

{

* PRESULT = 0;

Switch (m_tab.getcurseel ())

{

Case 0:

Page1.ShowWindow (SW_SHOW);

Page2.ShowWindow (sw_hide);

Break;

Case 1:

Page1.ShowWindow (sw_hide);

Page2.ShowWindow (SW_SHOW);

Break;

}

}

Void cdlete :: onok ()

{

Page1.destroyWindow ();

Page2.destroyWindow ();

This-> destroyWindow ();

}

//

转载请注明原文地址:https://www.9cbs.com/read-69457.html

New Post(0)