public Boolean RunSpecialUpdate(JZFile file, String server, String userName, String password, Guid moduleID) { String path = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~"), "update"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } String fName = Path.Combine(path, file.FileName); File.WriteAllBytes(fName, file.FileData); Boolean flag = JZCommonHelper.UnZipFile(fName); if (flag) { String[] files = new String[] { "sys_biz_ModuleCatlog", "sys_biz_SheetCatlog", "sys_dictionary", "sys_formulas", "sys_module", "sys_sheet", "sys_module_sheet", "sys_stadium_config", "sys_module_config" }; foreach (String item in files) { String fPath = Path.Combine(path, item + ".dat"); if (File.Exists(fPath)) { String bcp = "bcp " + Connection.Database + ".dbo." + item + "_update in " + fPath + " -c -S " + server + " -U " + userName + " -P " + password; flag = flag && JZCommonHelper.ExeCommand(bcp); logger.Error(bcp); } } if (flag) { String sql = @"UPDATE dbo.sys_module_update SET ID=b.ID, Name=b.Name, Description=b.Description FROM dbo.sys_module_update a JOIN dbo.sys_module b ON b.ID='" + moduleID + @"' UPDATE dbo.sys_formulas_update SET ModuleID='" + moduleID + @"' UPDATE dbo.sys_module_sheet_update SET ModuleID='" + moduleID + @"' UPDATE dbo.sys_module_config_update SET ModuleID='" + moduleID + @"' UPDATE dbo.sys_stadium_config_update SET ID='" + moduleID + @"'"; ExcuteCommand(sql); int i = RunStoreProcedure("sp_update"); flag = i > 0; } } return(flag); }
public void GenerateDBUpdate(DataTable dt) { if (dt != null && dt.Rows.Count > 0) { List <String> newTB = new List <string>(); newTB.Add("dbo.sys_formulas"); newTB.Add("dbo.sys_line_formulas"); newTB.Add("dbo.sys_module"); newTB.Add("dbo.sys_sheet"); newTB.Add("dbo.sys_stadium_config"); Boolean hasNewUpdate = false; for (int i = 0; i < dt.Rows.Count; i++) { String tbName = dt.Rows[i]["TableName"].ToString().ToLower(); String sql = String.Format("SELECT COUNT(1) FROM {0} WHERE Scts_1>'{1}' ", tbName, Convert.ToDateTime(dt.Rows[i]["LastTime"]).ToString("yyyy-MM-dd HH:mm:ss.fff")); if (newTB.Contains(tbName)) { sql = String.Format("SELECT COUNT(1) FROM {0} WHERE LastEditedTime>'{1}' ", tbName, Convert.ToDateTime(dt.Rows[i]["LastTime"]).ToString("yyyy-MM-dd HH:mm:ss.fff")); } sql = String.Format("SELECT COUNT(1) FROM sys_sheet WHERE LastEditedTime>'{0}' ", Convert.ToDateTime(dt.Rows[i]["LastTime"]).ToString("yyyy-MM-dd HH:mm:ss.fff")); Object obj = ExcuteScalar(sql); if (obj != null && obj != DBNull.Value) { hasNewUpdate = Convert.ToInt32(obj) > 0; if (hasNewUpdate) { break; } } } if (hasNewUpdate) { String userName = "******"; String pw = "wdxlzyn@#830"; String server = "ISSDCPLCDMK"; String valid = " -c -S " + server + " -U " + userName + " -P " + pw; String subFolder = GetSubFolder("3"); String path = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~"), "update\\" + subFolder); String file = Path.Combine(path, "sys_sheet.dat"); String bcp = "bcp \"SELECT * FROM " + Connection.Database + ".dbo.sys_sheet WHERE LastEditedTime > '" + Convert.ToDateTime(dt.Rows[0]["LastTime"]).ToString("yyyy-MM-dd HH:mm:ss.fff") + "' \" queryout " + file + valid; JZCommonHelper.ExeCommand(bcp); String fileName = Yqun.Common.ContextCache.ApplicationContext.Current.UserName + "_" + Yqun.Common.ContextCache.ApplicationContext.Current.Identification.MacAddress + "_" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-fff") + ".zip"; String zipFile = Path.Combine(path, fileName); if (File.Exists(zipFile)) { File.Delete(zipFile); } List <String> list = new List <string>(); list.Add(file); Boolean flag = JZCommonHelper.CreateZipFile(list, zipFile); SaveUpdateInfo(Guid.NewGuid().ToString(), fileName, "3", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); } } }