public Boolean UploadFileByLineID(JZFile f, String lineID) { Boolean result = true; if (f != null && f.FileData != null) { try { String sql = "SELECT ID,LineName,Description,IPAddress,Port FROM dbo.sys_line WHERE ID='" + lineID + "'"; DataTable dt = GetDataTable(sql); for (int i = 0; i < dt.Rows.Count; i++) { Boolean flag = true; String lineAddress = "net.tcp://" + dt.Rows[i]["IPAddress"] + ":" + dt.Rows[i]["Port"] + "/TransferService.svc"; object obj = CallRemoteServerMethod(lineAddress, "Yqun.BO.BusinessManager.dll", "UploadUpdateFile", new Object[] { f }); flag = Convert.ToBoolean(obj); result = result & flag; } } catch (Exception ex) { logger.Error("上传更新包失败:" + ex.Message + "; lineID=" + lineID); result = false; } } return(result); }
private void SaveUpdateZipFile(String flag) { //上传更新包 OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "压缩文件(*.zip)|*.zip"; dlg.Multiselect = false; if (dlg.ShowDialog() == DialogResult.OK) { if (dlg.FileName != "") { FileStream stream = null; JZFile f = new JZFile(); f.FileName = Path.GetFileName(dlg.FileName); stream = new FileInfo(dlg.FileName).OpenRead(); Byte[] buffer = new Byte[stream.Length]; stream.Read(buffer, 0, Convert.ToInt32(stream.Length)); f.FileType = flag; f.FileData = buffer; stream.Close(); Boolean result = UploadHelperClient.UploadUpdateFile(f); MessageBox.Show(result ? "成功" : "失败"); } } }
public JZFile GetSpecialFile(Guid moduleID) { 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" }; List <String> moduleIDs = new List <string>(); moduleIDs.Add(moduleID.ToString()); Boolean flag = true; String moduleIDStr = "'" + String.Join("','", moduleIDs.ToArray()) + "'"; try { String path = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~"), "update"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } List <String> list = new List <string>(); foreach (String tbName in files) { list.Add(Path.Combine(path, tbName + ".dat")); flag = flag && OutPutFile(tbName, path, moduleIDStr, true); } String zipFile = Path.Combine(path, moduleID + ".zip"); if (File.Exists(zipFile)) { File.Delete(zipFile); } flag = flag && JZCommonHelper.CreateZipFile(list, zipFile); if (flag) { FileStream stream = null; JZFile f = new JZFile(); f.FileName = moduleID + ".zip"; stream = new FileInfo(zipFile).OpenRead(); Byte[] buffer = new Byte[stream.Length]; stream.Read(buffer, 0, Convert.ToInt32(stream.Length)); f.FileType = "all"; f.FileData = buffer; stream.Close(); return(f); } } catch (Exception ex) { logger.Error("generate special file error for module " + moduleID + ": " + ex.Message); } return(null); }
private void bt_uploadGL_All_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "压缩文件(*.zip)|*.zip"; dlg.Multiselect = false; if (dlg.ShowDialog() == DialogResult.OK) { if (dlg.FileName != "") { String errorLineName = ""; FileStream stream = null; JZFile f = new JZFile(); f.FileName = Path.GetFileName(dlg.FileName); stream = new FileInfo(dlg.FileName).OpenRead(); Byte[] buffer = new Byte[stream.Length]; stream.Read(buffer, 0, Convert.ToInt32(stream.Length)); f.FileType = "1"; f.FileData = buffer; stream.Close(); DataTable dt = LineHelperClient.GetLineList(); String msg = ""; if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { Boolean result = UploadHelperClient.UploadFileByLineID(f, dt.Rows[i]["ID"].ToString()); if (!result) { errorLineName += "," + dt.Rows[i]["LineName"].ToString(); } } if (errorLineName != "") { msg = "发布失败,失败线路有" + errorLineName; } else { msg = "全部成功"; } MessageBox.Show(msg); } } } }
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 Boolean UpdateSpecialModule(Guid sourceModuleID, Guid destModuleID) { String moduleLibAddress = "net.tcp://Lib.kingrocket.com:8066/TransferService.svc"; //去模板库中取模板数据 object obj = CallRemoteServerMethod(moduleLibAddress, "Yqun.BO.BusinessManager.dll", "GetSpecialFile", new Object[] { destModuleID }); JZFile file = obj as JZFile; if (file != null) { List <String> auth = GetAuthInfoFromConnectionString(Connection.ConnectionString); String server = auth[0]; String userName = auth[1]; String password = auth[2]; //将取到的数据更新进自己的数据库中 return(RunSpecialUpdate(file, server, userName, password, sourceModuleID)); } else { return(false); } }
public Boolean UploadUpdateFile(JZFile f) { Boolean result = false; if (f != null && f.FileData != null) { try { String subFolder = GetSubFolder(f.FileType); String path = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~"), "update\\" + subFolder); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } String fName = Path.Combine(path, f.FileName); File.WriteAllBytes(fName, f.FileData); ExcuteCommand("UPDATE dbo.sys_update SET FileState=0 WHERE FileType=" + f.FileType); String sql = String.Format(@"INSERT INTO dbo.sys_update ( ID , FileName , FileType , CreatedServerTime , FileState ) VALUES ( '{0}','{1}',{2},GETDATE(),1)", Guid.NewGuid(), f.FileName, f.FileType); ExcuteCommand(sql); result = true; } catch (Exception ex) { logger.Error("上传更新包失败:" + ex.Message); result = false; } } return(result); }
public static Boolean UploadFileByLineID(JZFile f, String lineID) { return(Convert.ToBoolean(Agent.CallService("Yqun.BO.BusinessManager.dll", "UploadFileByLineID", new object[] { f, lineID }))); }
public static Boolean UploadUpdateFile(JZFile f) { return(Convert.ToBoolean(Agent.CallService("Yqun.BO.BusinessManager.dll", "UploadUpdateFile", new object[] { f }))); }
private void lb_img_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { OpenFileDialog _OpenFileDialog = new OpenFileDialog(); _OpenFileDialog.Filter = "图片文件(*.jpg,*.gif,*.bmp)|*.jpg|*.gif|*.bmp"; //int MAX_IMAGE_SIZE = 100;//图片最大上传大小,单位KB int MAX_IMAGE_WIDTH = 800; //图片最大宽度 int MAX_IMAGE_HEIGHT = 600; //图片最大高度 float MAX_RATE = (float)MAX_IMAGE_HEIGHT / MAX_IMAGE_WIDTH; //高宽比 if (_OpenFileDialog.ShowDialog() == DialogResult.OK) { MemoryStream tempms = new MemoryStream(File.ReadAllBytes(_OpenFileDialog.FileName)); //long size = tempms.Length / 1024; //if (size > MAX_IMAGE_SIZE) //{ // MessageBox.Show(string.Format("图片大小不能超出{0}KB", MAX_IMAGE_SIZE), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; //} Bitmap bitmap = new Bitmap(tempms); #region 判断要裁剪的图片的高度 int imgWidth, imgHeight, imgCutWidth, imgCutHeight; imgWidth = bitmap.Width; imgHeight = bitmap.Height; if (imgWidth <= MAX_IMAGE_WIDTH && imgHeight <= MAX_IMAGE_HEIGHT) { imgCutWidth = imgWidth; imgCutHeight = imgHeight; } else { float imgRate; imgRate = (float)imgHeight / imgWidth; if (imgRate < MAX_RATE) {//高小了 if (imgWidth < MAX_IMAGE_WIDTH) { imgCutWidth = imgWidth; } else { imgCutWidth = MAX_IMAGE_WIDTH; } imgCutHeight = (int)(imgCutWidth * imgRate); } else { if (imgHeight < MAX_IMAGE_HEIGHT) { imgCutHeight = imgHeight; } else { imgCutHeight = MAX_IMAGE_HEIGHT; } imgCutWidth = (int)(imgCutHeight / imgRate); } } #endregion Bitmap imgCut = JZCommonHelper.KiResizeImage(bitmap, imgCutWidth, imgCutHeight, 0); //ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg); //System.Drawing.Imaging.Encoder myEncoder = // System.Drawing.Imaging.Encoder.Quality; //EncoderParameters myEncoderParameters = new EncoderParameters(1); //EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 100L); //myEncoderParameters.Param[0] = myEncoderParameter; //using (MemoryStream stream = new MemoryStream()) //{ // b.Save(stream, jgpEncoder, myEncoderParameters); // b = new Bitmap(stream); //} MemoryStream stream = new MemoryStream(); imgCut.Save(stream, ImageFormat.Jpeg); JZFile file = new JZFile(); file.FileData = stream.ToArray(); String newImgID = DocumentHelperClient.SaveInvalidImage(invalidReportID, file, GetSeletedText()); if (newImgID != "") { //AddImage(new Bitmap(tempms), tabControl1.SelectedIndex, newImgID, true); AddImage(new Bitmap(stream), tabControl1.SelectedIndex, newImgID, true); tempms.Close(); tempms.Dispose(); stream.Close(); stream.Dispose(); } else { MessageBox.Show("图片上传失败"); } } }
public static String SaveInvalidImage(String invalidID, JZFile file, String type) { return(Agent.CallService("Yqun.BO.BusinessManager.dll", "SaveInvalidImage", new object[] { invalidID, file, type }).ToString()); }
/// <summary> /// 更新一条线的所有模板、表单、公式等信息 /// </summary> /// <param name="lineID"></param> /// <returns></returns> public Boolean UpdateLine(Guid lineID, List <String> moduleIDs, Boolean isModule, Boolean isRelationSheet) { List <String> files = new List <String>(); if (isModule) { files.Add("sys_dictionary"); files.Add("sys_formulas"); files.Add("sys_module"); files.Add("sys_stadium_config"); files.Add("sys_module_config"); if (isRelationSheet) { files.Add("sys_module_sheet"); } } else { files.Add("sys_sheet"); } Sys_Line line = GetLineByID(lineID); Boolean flag = true; String moduleIDStr = "'" + String.Join("','", moduleIDs.ToArray()) + "'"; if (line != null) { try { String path = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~"), "update/" + line.LineName); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } List <String> list = new List <string>(); foreach (String tbName in files) { list.Add(Path.Combine(path, tbName + ".dat")); flag = flag && OutPutFile(tbName, path, moduleIDStr, isModule); } String zipFile = Path.Combine(path, line.LineName + ".zip"); if (File.Exists(zipFile)) { File.Delete(zipFile); } flag = flag && JZCommonHelper.CreateZipFile(list, zipFile); if (flag) { FileStream stream = null; JZFile f = new JZFile(); f.FileName = line.LineName + ".zip"; stream = new FileInfo(zipFile).OpenRead(); Byte[] buffer = new Byte[stream.Length]; stream.Read(buffer, 0, Convert.ToInt32(stream.Length)); f.FileType = "all"; f.FileData = buffer; stream.Close(); String lineAddress = "net.tcp://" + line.LineIP + ":" + line.LinePort + "/TransferService.svc"; object obj = CallRemoteServerMethod(lineAddress, "Yqun.BO.BusinessManager.dll", "RunUpdate", new Object[] { f, line.LineIP, line.UserName, line.PassWord, isModule, isRelationSheet }); flag = Convert.ToBoolean(obj); } } catch (Exception ex) { logger.Error("generate updated file error for line " + line.LineName + ": " + ex.Message); flag = false; } } else { flag = false; } return(flag); }
/// <summary> /// 通过传来的文件流,更新服务端数据库 /// </summary> /// <param name="file"></param> /// <returns></returns> public Boolean RunUpdate(JZFile file, String server, String userName, String password, Boolean isModule, Boolean isRelationSheet) { 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 spName = "sp_update"; List <String> files = new List <String>(); if (isModule) { files.Add("sys_dictionary"); files.Add("sys_formulas"); files.Add("sys_module"); files.Add("sys_stadium_config"); files.Add("sys_module_config"); if (isRelationSheet) { files.Add("sys_module_sheet"); spName = "sp_update_module_sheet"; } else { spName = "sp_update_module"; } } else { files.Add("sys_sheet"); spName = "sp_update_sheet"; } 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; bcp = "master..xp_cmdshell '" + bcp.Replace("'", "''") + "' "; //flag = JZCommonHelper.ExeCommand(bcp); //logger.Error(bcp); flag = ExcuteCommand(bcp) >= 1; } } if (flag) { logger.Error("start store procedure: " + spName); int i = RunStoreProcedure(spName); logger.Error("end " + spName + ": " + i); flag = i > 0; } } return(flag); }