| | |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | | using System.Data.SqlClient; |
| | | using System.IO; |
| | | using System.Web; |
| | | using System.Web.Http; |
| | | using WebAPI.Models; |
| | | |
| | |
| | | return objJsonResult; |
| | | } |
| | | //主表 |
| | | |
| | | |
| | | ds = oCN.RunProcReturn("exec h_p_MES_StationOutBill_QtyCtrl " + HInterID + "", "h_p_MES_StationOutBill_QtyCtrl"); |
| | | if (ds == null) |
| | | { |
| | |
| | | " Where a.HInterID=" + HProcExchInterID + " and b.HEntryID=" + HProcExchEntryID + " ", "Sc_ProcessExchangeBillMain"); |
| | | if (ds1 == null || ds1.Tables[0].Rows.Count == 0 || HLastSubProc == false) |
| | | { |
| | | |
| | | |
| | | } |
| | | else if (ClsPub.isStrNull(ds1.Tables[0].Rows[0]["HLastProc"]) == "是") |
| | | { |
| | | { |
| | | |
| | | } |
| | | oCN.Commit(); |
| | |
| | | |
| | | |
| | | // |
| | | |
| | | |
| | | [Route("Cj_StationOutBill/UploadFile")] |
| | | [HttpPost] |
| | | public object UploadFile() |
| | | { |
| | | try |
| | | { |
| | | int num = 0; |
| | | string HBillNo = HttpContext.Current.Request.Params["HBillNo"]; //单据号 |
| | | string HRemark = HttpContext.Current.Request.Params["HRemark"]; //备注 |
| | | string HUserName = HttpContext.Current.Request.Params["HUserName"]; //单据号 |
| | | string uploadPath = HttpContext.Current.Server.MapPath("~/App_Data/"); |
| | | HttpRequest request = System.Web.HttpContext.Current.Request; |
| | | HttpFileCollection files = request.Files; |
| | | |
| | | string savePath = ""; |
| | | if (files == null || files.Count <= 0) |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "文件不能为空!"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | else |
| | | { |
| | | for (int i = 0; i < files.Count; i++) |
| | | { |
| | | |
| | | // 获取文件 |
| | | HttpPostedFile httpPostedFile = files[i]; |
| | | |
| | | string filePath = Path.GetFullPath(httpPostedFile.FileName);//文件上传路径 |
| | | string fileExtension = Path.GetExtension(httpPostedFile.FileName);// 文件扩展名 |
| | | string filename = httpPostedFile.FileName; |
| | | string fileSavePath = uploadPath;// 上传保存路径 |
| | | int filesize = files[i].ContentLength;//获取上传文件的大小单位为字节byte |
| | | int Maxsize = 40000 * 1024;//定义上传文件的最大空间大小为40M |
| | | if (filesize >= Maxsize) |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "上传文件超过40M,不能上传!"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | if (Directory.Exists(fileSavePath) == false)//如果不存在就创建file文件夹 |
| | | { |
| | | Directory.CreateDirectory(fileSavePath); //添加文件夹 |
| | | } |
| | | savePath = Path.Combine(fileSavePath, filename); |
| | | //查询文件关联表,是否已存在上传数据 |
| | | ds = oCN.RunProcReturn("select * from MES_AccessoriesList where HSourceBillNo = " + HBillNo, "MES_AccessoriesList"); |
| | | if (ds == null || ds.Tables[0].Rows.Count == 0) |
| | | { |
| | | //写入服务器文件 |
| | | httpPostedFile.SaveAs(savePath); |
| | | //写入数据表 |
| | | oCN.RunProc("Insert into MES_AccessoriesList (HFileName,HFilePath,HFilePath_Cus,HFileType" + |
| | | ",HLoadMan,HLoadDate,HRemark,HVerNum,HFileSize" + |
| | | ",HFileClsID,HSourceBillNo" + |
| | | ") values('" |
| | | + filename.ToString() + "','" + savePath.ToString() + "','" + filePath.ToString() + "','" + fileExtension.ToString()+ "'" + |
| | | ",'" + HUserName + "',getdate(),'" + HRemark + "','V1','" + filesize + |
| | | "','" + 0 + "','" + HBillNo + |
| | | "') "); |
| | | } |
| | | else |
| | | { |
| | | //删除服务器文件 |
| | | FileInfo file = new FileInfo(HttpContext.Current.Server.MapPath(savePath)); |
| | | file.Delete(); |
| | | //删除数据表数据 |
| | | ds = oCN.RunProcReturn("delete from MES_AccessoriesList where HSourceBillNo = " + HBillNo, "MES_AccessoriesList"); |
| | | |
| | | //写入服务器文件 |
| | | httpPostedFile.SaveAs(savePath); |
| | | //写入数据表 |
| | | //写入数据表 |
| | | oCN.RunProc("Insert into MES_AccessoriesList (HFileName,HFilePath,HFilePath_Cus,HFileType" + |
| | | ",HLoadMan,HLoadDate,HRemark,HVerNum,HFileSize" + |
| | | ",HFileClsID,HSourceBillNo" + |
| | | ") values('" |
| | | + filename.ToString() + "','" + savePath.ToString() + "','" + filePath.ToString() + "','" + fileExtension.ToString() + "'" + |
| | | ",'" + HUserName + "',getdate(),'" + HRemark + "','V1','" + filesize + |
| | | "','" + 0 + "','" + HBillNo + |
| | | "') "); |
| | | } |
| | | //if (Directory.Exists(savePath) == true) //如果存在重名文件就提示 |
| | | //{ |
| | | // objJsonResult.code = "0"; |
| | | // objJsonResult.count = 0; |
| | | // objJsonResult.Message = "存在同名文件!"; |
| | | // objJsonResult.data = null; |
| | | // return objJsonResult; |
| | | //} |
| | | httpPostedFile.SaveAs(savePath); |
| | | string StrPath = "/File/" + filename; |
| | | //写入数据表 |
| | | |
| | | num = num + 1; |
| | | } |
| | | if (num == files.Count) |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "上传成功!"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | else |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "上传失败!"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = e.Message; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |