public void SavePlugData(Plug plug) { HashObject hash = new HashObject(); long fileLength = 0; //数据搬移 plug.PDownpath = MoveFile(plug.PDownpath, out fileLength); plug.PTotal = fileLength; plug.PVideo = MoveFile(plug.PVideo, out fileLength); plug.PIcon = MoveFile(plug.PIcon, out fileLength); plug.PPic1 = MoveFile(plug.PPic1, out fileLength); plug.PPic2 = MoveFile(plug.PPic2, out fileLength); plug.PPic3 = MoveFile(plug.PPic3, out fileLength); hash.Add("pdownpath", plug.PDownpath); hash.Add("pvideo", plug.PVideo); hash.Add("picon", plug.PIcon); hash.Add("ppics", plug.PPics); hash.Add("pcreatedate", DateTime.Now); //数据保存 using (DbHelper db = AppUtils.CreateDbHelper()) { try { db.BeginTransaction(); List <string> needToDeleteFiles = DeleteOldData(plug, db, hash); if (plug.PTotal == 0) { plug.PTotal = hash.GetValue <int>("ptotal", 0); } string sql = "insert into plugs (pid,pname,pversion,pkind,plabel,picon,pdes,pvideo,pvideoweb,pcost,plevel,pdownpath,pdownpathweb,ptotal,pext,ppics,pcreatedate,pupdatedate,pshowway,pstorename,pwindowname) values(@pid,@pname,@pversion,@pkind,@plabel,@picon,@pdes,@pvideo,@pvideoweb,@pcost,@plevel,@pdownpath,@pdownpathweb,@ptotal,@pext,@ppics,@pcreatedate,@pupdatedate,@pshowway,@pstorename,@pwindowname)"; db.AddParameter("pid", plug.PId); db.AddParameter("pname", plug.PName); db.AddParameter("pversion", plug.PVersion); db.AddParameter("pkind", plug.PKind); db.AddParameter("plabel", plug.PLabel); db.AddParameter("picon", hash.GetValue <string>("picon")); db.AddParameter("pdes", plug.PDes); db.AddParameter("pvideo", hash.GetValue <string>("pvideo")); db.AddParameter("pcost", plug.PCost); db.AddParameter("plevel", plug.PLevel); db.AddParameter("pdownpath", hash.GetValue <string>("pdownpath")); db.AddParameter("ptotal", plug.PTotal); db.AddParameter("pext", plug.PExt); db.AddParameter("ppics", hash.GetValue <string>("ppics")); db.AddParameter("pcreatedate", hash.GetValue <DateTime>("pcreatedate")); db.AddParameter("pupdatedate", plug.PUpdatedate); db.AddParameter("pshowway", plug.PShowway); db.AddParameter("pstorename", plug.PStorename); db.AddParameter("pwindowname", plug.PWindowname); db.AddParameter("pvideoweb", GetWebUri()); db.AddParameter("pdownpathweb", GetWebUri()); db.ExecuteScalerSQL(sql); foreach (string file in needToDeleteFiles) { File.Delete(file); } db.CommitTransaction(); } catch (Exception e) { if (db.HasBegunTransaction) { db.RollbackTransaction(); } throw e; } } }