public ResultMsg_Equ editEquDataInDB(EquInfo dataEntity, ResultMsg_Equ result) { if (dataEntity.ID.Length == 0) { dataEntity.ID = "0"; } //if (dataEntity.ProcessCode.Length == 0) dataEntity.ProcessCode = ""; //if (dataEntity.ProcessName.Length == 0) dataEntity.ProcessName = ""; //if (dataEntity.ProcessBeat.Length == 0) dataEntity.ProcessBeat = ""; //if (dataEntity.ProcessDsca.Length == 0) dataEntity.ProcessDsca = ""; //if (dataEntity.InturnNumber.Length == 0) dataEntity.InturnNumber = "0"; //if (dataEntity.ProcessManual.Length == 0) dataEntity.ProcessManual = ""; using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ELCO_ConnectionString"].ToString())) { SqlCommand cmd = new SqlCommand(); SqlTransaction transaction = null; try { conn.Open(); cmd.Connection = conn; string strSql = " SELECT COUNT(1) AS SM FROM Equ_DeviceInfoList WHERE DeviceCode = '" + dataEntity.DeviceCode + "' and ID <> " + dataEntity.ID; cmd.CommandType = CommandType.Text; cmd.CommandText = strSql; SqlDataAdapter Datapter = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); Datapter.Fill(dt); if (dt != null && dt.Rows.Count > 0) { if (Convert.ToInt32(dt.Rows[0]["SM"]) > 0) { result.result = "failed"; result.msg = "此设备编号已经存在, 请核对!"; } else { result.result = ""; result.msg = ""; } } else { result.result = "failed"; result.msg = "数据重复性检查失败!"; } if (result.result == "") { transaction = conn.BeginTransaction(); cmd.Transaction = transaction; strSql = string.Format( @" UPDATE Equ_DeviceInfoList SET ProcessCode = '{0}' , DeviceCode = '{1}' , DeviceName = '{2}' , DeviceVendor = '{3}' , DeviceUseDate = {4} , DevicePartsFile= '{5}' , DeviceManualFile= '{6}' , DeviceComment= '{7}' , UpdateUser = '******' , UpdateTime = getdate() WHERE id = {9} ", dataEntity.ProcessCode, dataEntity.DeviceCode, dataEntity.DeviceName, dataEntity.DeviceVendor, dataEntity.DeviceUseDate, dataEntity.DevicePartsFile, dataEntity.DeviceManualFile, dataEntity.DeviceComment, UserName, dataEntity.ID ); cmd.CommandType = CommandType.Text; cmd.CommandText = strSql; cmd.ExecuteNonQuery(); string strFileMoveResult = "", strFileMoveResult1 = ""; strFileMoveResult = doManualFileMove(dataEntity.UploadedFile, dataEntity.DeviceCode); strFileMoveResult1 = doPartsFileMove(dataEntity.UploadedManualFile, dataEntity.DeviceCode); if (strFileMoveResult.Length == 0 && strFileMoveResult1.Length == 0) { transaction.Commit(); result.result = "success"; result.msg = "保存数据成功!"; } else { transaction.Rollback(); result.result = "failed"; result.msg = "服务器端文件处理发生错误.\n" + strFileMoveResult; } } } catch (Exception ex) { transaction.Rollback(); result.result = "failed"; result.msg = "保存失败! \n" + ex.Message; } } return(result); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; if (context.Session["UserName"] != null) { UserName = context.Session["UserName"].ToString().ToUpper().Trim(); } else { UserName = ""; } Action = RequstString("Action"); if (Action.Length == 0) { Action = ""; } if (Action == "Equ_Detail") { EquInfo equinfo = new EquInfo(); equinfo.ID = RequstString("EquID"); EquInfo result = new EquInfo(); result = GetEquDetailObj(equinfo, result); context.Response.Write(jsc.Serialize(result)); } else if (Action == "PartsFileUploadify" || Action == "ManuUploadify") { HttpPostedFile file = System.Web.HttpContext.Current.Request.Files["Filedata"]; ResultMsg_FileUPload result = new ResultMsg_FileUPload(); result = doUploadFile(result, file); context.Response.Write(jsc.Serialize(result)); } else if (Action == "Equ_Add") { EquInfo dataEntity = new EquInfo(); //dataEntity.ID = RequstString("ProcId"); dataEntity.ProcessCode = RequstString("ProcessName"); dataEntity.DeviceCode = RequstString("DeviceCode"); dataEntity.DeviceName = RequstString("DeviceName"); dataEntity.DeviceVendor = RequstString("DeviceVendor"); dataEntity.DeviceUseDate = RequstString("PmStartDate"); dataEntity.DevicePartsFile = RequstString("DevicePartsFile"); dataEntity.DeviceManualFile = RequstString("DeviceManualFile"); dataEntity.DeviceComment = RequstString("Description"); dataEntity.UploadedFile = RequstString("UploadedFile"); dataEntity.UploadedManualFile = RequstString("UploadedManualFile"); ResultMsg_Equ result = new ResultMsg_Equ(); result = addEquDataInDB(dataEntity, result); context.Response.Write(jsc.Serialize(result)); } else if (Action == "Equ_Edit") { EquInfo dataEntity = new EquInfo(); dataEntity.ID = RequstString("EquID"); dataEntity.ProcessCode = RequstString("ProcessName"); dataEntity.DeviceCode = RequstString("DeviceCode"); dataEntity.DeviceName = RequstString("DeviceName"); dataEntity.DeviceVendor = RequstString("DeviceVendor"); dataEntity.DeviceUseDate = RequstString("PmStartDate"); dataEntity.DevicePartsFile = RequstString("DevicePartsFile"); dataEntity.DeviceManualFile = RequstString("DeviceManualFile"); dataEntity.DeviceComment = RequstString("Description"); dataEntity.UploadedFile = RequstString("UploadedFile"); dataEntity.UploadedManualFile = RequstString("UploadedManualFile"); ResultMsg_Equ result = new ResultMsg_Equ(); result = editEquDataInDB(dataEntity, result); context.Response.Write(jsc.Serialize(result)); } else if (Action == "PartsFileCHECK" || Action == "PartsFileDOWNLOAD") { string objID = RequstString("ObjID"); string fileName = GetEquPartsFileNameFromDB(objID); string fileType = Path.GetExtension(fileName).ToLower(); string fileWithoutType = Path.GetFileNameWithoutExtension(fileName); if (!Directory.Exists(browsePartsFilePath)) { Directory.CreateDirectory(browsePartsFilePath); } context.Response.ClearContent(); context.Response.ClearHeaders(); if (Action == "PartsFileCHECK") { //context.Response.AppendHeader("Content-Disposition", string.Format("inline;filename={0}", fileName)); if (fileType == ".xlsx" || fileType == ".xls") { string path = browsePartsFilePath + Common.StringFilter.FilterSpecial(fileName); try { Workbook wb = new Workbook(path); wb.Save(browsePartsFilePath + fileWithoutType + ".pdf", Aspose.Cells.SaveFormat.Pdf); context.Response.Write("./PartsFile/" + fileWithoutType + ".pdf"); } catch (Exception ex) { context.Response.Write("false"); } } else { context.Response.Write("./PartsFile/" + fileWithoutType + ".pdf"); } } else { context.Response.AppendHeader("Content-Disposition", string.Format("attached;filename={0}", HttpContext.Current.Server.UrlEncode(fileName.ToString()))); if (fileType == ".docx" || fileType == ".doc") { context.Response.AppendHeader("content-type", "application/msword"); } else if (fileType == ".xlsx" || fileType == ".xls") { context.Response.AppendHeader("content-type", "application/x-msexcel"); } else if (fileType == ".pdf") { context.Response.AppendHeader("content-type", "application/pdf"); } context.Response.ContentType = "application/octet-stream"; context.Response.ContentEncoding = System.Text.Encoding.Default; try { FileInfo fileInfo = new FileInfo(browsePartsFilePath + Common.StringFilter.FilterSpecial(fileName)); context.Response.AddHeader("content-length", fileInfo.Length.ToString());//文件大小 context.Response.WriteFile(browsePartsFilePath + Common.StringFilter.FilterSpecial(fileName)); } catch (Exception ex) { context.Response.Write(ex.Message); } context.Response.Flush(); context.Response.Close(); } } else if (Action == "ManuCHECK" || Action == "ManuDOWNLOAD") { string objID = RequstString("ObjID"); string fileName = GetEquManuFileNameFromDB(objID); string fileType = Path.GetExtension(fileName).ToLower(); FileInfo fileInfo = new FileInfo(browseManualFilePath + fileName); string fileWithoutType = Path.GetFileNameWithoutExtension(fileName); if (!Directory.Exists(browsePartsFilePath)) { Directory.CreateDirectory(browsePartsFilePath); } context.Response.ClearContent(); context.Response.ClearHeaders(); if (Action == "ManuCHECK") { if (fileType == ".docx" || fileType == ".doc") { string path = browseManualFilePath + Common.StringFilter.FilterSpecial(fileName); try { //读取doc文档 Document doc = new Document(path); ////保存为PDF文件,此处的SaveFormat支持很多种格式,如图片,epub,rtf 等等 doc.Save(browseManualFilePath + fileWithoutType + ".pdf", Aspose.Words.SaveFormat.Pdf); //Workbook wb = new Workbook(path); //wb.Save(browseManualFilePath + fileWithoutType + ".pdf", SaveFormat.Pdf); context.Response.Write("./ManualFile/" + fileWithoutType + ".pdf"); } catch (Exception ex) { context.Response.Write("false"); } } else { context.Response.Write("./ManualFile/" + fileWithoutType + ".pdf"); } } else { //context.Response.AppendHeader("Content-Disposition", string.Format("attached;filename={0}", fileName)); //context.Response.AddHeader("content-length", fileInfo.Length.ToString());//文件大小 context.Response.AppendHeader("Content-Disposition", string.Format("attached;filename={0}", HttpContext.Current.Server.UrlEncode(fileName.ToString()))); if (fileType == ".docx" || fileType == ".doc") { context.Response.AppendHeader("content-type", "application/msword"); } else if (fileType == ".xlsx" || fileType == ".xls") { context.Response.AppendHeader("content-type", "application/x-msexcel"); } else if (fileType == ".pdf") { context.Response.AppendHeader("content-type", "application/pdf"); } try { if (!Directory.Exists(browseManualFilePath)) { Directory.CreateDirectory(browseManualFilePath); } FileInfo fileInfo1 = new FileInfo(browseManualFilePath + fileName); context.Response.AddHeader("content-length", fileInfo1.Length.ToString());//文件大小 context.Response.WriteFile(browseManualFilePath + fileName); } catch (Exception ex) { context.Response.Write(ex.Message); } context.Response.Flush(); context.Response.Close(); } } }