Pubwin member merger program written in the previous period
For text versions, see http://www.cnblogs.com/sprite/p/3477734.html
#-*-coding:gbk-*-# Pubwin member Repare tools# change member level by score# code by Spriteimport Pymssqlimport _mssqlimpo RT Uuidimport Decimalimport osfrom time import sleepdef getpath (): #获取当地程序所在目录 return Os.path.abspath ('. ') def dbtest (dbpasswd): #检查数据库是否可以登录 cmd= "Osql-u netcafe-p" +dbpasswd+ "-Q" + "\" "+" "+" \ "" A=os.system (cmd Return a def databasecon (passwd= ' 123456 '): #返回数据库连接字串 try:con=pymssql.connect (host= '. ', user= ' netcafe ', password=passwd,database= ' local ') Except:return 0 return con def dbattach (OPR=1,DBPASSW D= ' 123456 '): #1 the Local_db.mdf file database under the Add-in directory, 0 indicates success #opr =0 represents detach Souredb Path=getpath () dbmdfpath=path+ ' \ \ ' + ' local_d Ata. MDF ' dbldfpath=path+ ' \ \ ' + ' Local_log. LDF ' If opr==1:cmd= ' osql-u netcafe-p "+dbpasswd+"-Q "+" \ "+" sp_attach_db @dbname = ' souredb ', @filename 1= "+" ' "+dbmdfpath+" ', "+" @filename2 = "+" ' "+dbldfpath+" "" + "\" "else:cmd=" Osql-u netcafe-p "+dbpasswd+ "-Q" + "\" "+" sp_detach_db @dbname = ' souredb ' "+" \ "" A=os.popen (CMD) aline=a.readlines () If Len (al INE) ==0:return 0 Else:return 1 def creatmembertable (Dbpassword): #将soure库里的会员库提取到local库新建的member表 , the Soredb library must be attached successfully to merge #isplus为Y时合并相同会员金额, and the same card number member Con=databasecon (dbpassword) if Con==0:return 0 try is deleted directly for N: Cur=con.cursor () Cur.execute ("SELECT * to Local.dbo.member from Souredb.dbo.mem_localmemberbaseinfo") Con.commit () except:con.close () return 0 con.close () return 1 def getmaxidinlocalmember (p Assword): #获得local表最大id, the following add-on ID can be added precisely to avoid reporting ID uniqueness error Con=databasecon (password) if Con==0:return 0 cur=con.cursor () Cur.execute (' Select Max (id) from Mem_localmemberbaseinfo ') A=cur.fetchall () con.close () if a[0][0]>0: Return a[0][0] return 0def memberblanceplus (Dbpassword): Con=databasecon (Dbpassword) plussql= ' Update Mem_localm Emberbaseinfo Set BALance=mem_localmemberbaseinfo.balance+a.balance, Score=mem_localmemberbaseinfo.score+a.score from member as a W Here Mem_localmemberbaseinfo.uniqueid=a.uniqueid ' if Con==0:return 0 try:cur=con.cursor () cur.execute (Plussql) Con.commit () except:con.close () return 0 con.close () return 1 def memberjoin (d bpassword): Con=databasecon (dbpassword) if Con==0:return 0 maxid= (Getmaxidinlocalmember (Dbpassword)) delsql= ' d Elete member where UniqueID in (select UniqueID from Mem_localmemberbaseinfo) ' idplussql= ' update member set id=id+ ' + STR (MAXID) insql= ' insert into Mem_localmemberbaseinfo (level,levelid,realname,balance,score,updatetm,location, Certificateid,sex,birthday,country,password,validtm,opentm,certificatetype,id,uniqueid) Select Level,levelid, Realname,balance,score,updatetm,location, Certificateid,sex,birthday,country,password,validtm,opentm, Certificatetype,id,uniqueid from member ' try: Cur=con.cursor () Cur.execute (delsql) if maxid! = 0:cur.execute (idplussql) Cur.execute (insql) Con.commit () except:con.close () return 0 con.close () return 1 def dropmembertable (dbpasswor d): Con=databasecon (dbpassword) if Con==0:return 0 dropsql= ' drop table member ' Try:cur=con.cursor () Cur.execute (Dropsql) con.commit () except:con.close () return 0 con.close () return 1 Def initpro (): Os.system ("CLS") print "print" * "*55 print" Pubwin member Merge program "print" * " 5 print "Print" Before merging, please stop the Pubwin service, start the database service "print" Please want to merge data file Local_data.mdf,local_log. LDF put in the program directory "print" Before merging, please back up the database, merge is not successful please replace the original library "print" print "*" *55 print "\ n" Print "Please enter the database password" while 1:i Nitpro () dbpasswd=raw_input () if Dbtest (dbpasswd) ==0:print "database connection succeeded" break Else:print "database Connection Failed "sleep (2) Attach=dbattach (1,DBPASSWD) if Attach!=0: #返回值有问题, regardless of successful unsuccessful will return 0, the other way to determine the print ' x ' *30 print "to merge the database cannot be attached \ n Please local_data.mdf the data file, Local_log. The LDF is placed in the program directory \ nthe program will automatically exit "print ' X ' *30 sleep (3) exit () ismembertables=creatmembertable (DBPASSWD) if ismembertables==0: Print "Source Library membership table cannot be extracted or the Internet Bar database error \ nthe program will automatically exit" Attach=dbattach (0,DBPASSWD) sleep (3) exit () print "Source Library member Library Data extraction Successful" Attach=dbatta CH (0,dbpasswd) while 1:print "*" *30 print "same card number member amount added, (y/n)" Isplus=raw_input () if isplus = = ' Y ' or isplus = = ' N ': Break if isplus== ' Y ': Isplussuccess=memberblanceplus (dbpasswd) if Isplussuccess==0:print ' membership sum fails, the program will Auto Exit ' sleep (3) exit () print ' Member amount added successfully ' print ' Start merging database ' if Memberjoin (dbpasswd) ==0:dropmembertable (Dbpas SWD) print ' member merge failed, program will automatically exit ' sleep (3) exit () dropmembertable (dbpasswd) print ' Merge successful, do not repeat ' print ' Press any K EY to exit ' Os.system ("Pause>>null")
Already packaged with Py2exe: Http://pan.baidu.com/s/1dD2AVi5
Usage:
Requirement: to merge B Internet bar members into a database where Internet cafes are in use
1, will be a bar all members under the machine, stop Pubwin service, back up the database, and then start Slqserver
2, the B Internet Bar database into the program in the same directory (the directory is best not to have Chinese)
3, run Pubwindbmemjoin.exe, according to procedure procedure
4, if the membership level does not correspond, you need to manually modify after operation
Replace the database with the original library and manually merge if the program errors or exits without cause at the time of merging
PS: If the program configuration fails, or the application does not properly initialize the 0xc0000135 error, you need to install the VC++2008 runtime
The runtime is already in the compressed package.
Update
1.0 complete the basic function of the program, attach new library, combine amount, merge member
1.1 Add a function to determine the size of the membership ID, you can insert member's new library members to make the member ID accurately increased, no ID uniqueness error
: Http://pan.baidu.com/s/1dD2AVi5
Usage:
Requirement: to merge B Internet bar members into a database where Internet cafes are in use
1, will be a bar all members under the machine, stop Pubwin service, back up the database, and then start Slqserver
2, the B Internet Bar database into the program in the same directory (the directory is best not to have Chinese)
3, run Pubwindbmemjoin.exe, according to procedure procedure
4, if the membership level does not correspond, you need to manually modify after operation
Replace the database with the original library and manually merge if the program errors or exits without cause at the time of merging
PS: If the program configuration fails, or the application does not properly initialize the 0xc0000135 error, you need to install the VC++2008 runtime
The runtime is already in the compressed package.
Update
1.0 complete the basic function of the program, attach new library, combine amount, merge member
1.1 Add a function to determine the size of the membership ID, you can insert member's new library members to make the member ID accurately increased, no ID uniqueness error
1.2 Fix an SQL statement error, now correctly import the Membership level ID field
Python implementation of Pycode:pubwin member merging