|  |  | 
 |  |  | using System.Collections.Generic; | 
 |  |  | using System.Data; | 
 |  |  | using System.Data.SqlClient; | 
 |  |  | using System.IO; | 
 |  |  | using System.Web; | 
 |  |  | using System.Web.Http; | 
 |  |  | using System.Windows.Forms; | 
 |  |  | using WebAPI.Models; | 
 |  |  | 
 |  |  |         private json objJsonResult = new json(); | 
 |  |  |         SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); | 
 |  |  |         DataSet ds; | 
 |  |  |  | 
 |  |  |         string fileip = System.Configuration.ConfigurationManager.AppSettings["FileIP"]; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         ////检测 当前选中行的 项目状态 | 
 |  |  | 
 |  |  |                 string sql1 = string.Format(@"select * from h_v_Gy_MaterialList where 组织名称='" + Organization + "'"); | 
 |  |  |                 if (sWhere == null || sWhere.Equals("")) | 
 |  |  |                 { | 
 |  |  |                     ds = oCN.RunProcReturn(sql1 + sWhere + " order by 物料代码 ", "h_v_Gy_MaterialList"); | 
 |  |  |                     ds = oCN.RunProcReturn(sql1 + sWhere + " order by 物料代码 desc", "h_v_Gy_MaterialList"); | 
 |  |  |                 } | 
 |  |  |                 else | 
 |  |  |                 { | 
 |  |  |                     string sql = sql1 + sWhere + " order by 物料代码 "; | 
 |  |  |                     string sql = sql1 + sWhere + " order by 物料代码 desc"; | 
 |  |  |                     ds = oCN.RunProcReturn(sql, "h_v_Gy_MaterialList"); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  | 
 |  |  |                     { | 
 |  |  |                         objJsonResult.code = "0"; | 
 |  |  |                         objJsonResult.count = 0; | 
 |  |  |                         objJsonResult.Message = "保存失败!物料属性不能为空!"; | 
 |  |  |                         objJsonResult.Message = "保存失败!物料分类不能为空!"; | 
 |  |  |                         objJsonResult.data = 1; | 
 |  |  |                         return objJsonResult; | 
 |  |  |                     } | 
 |  |  | 
 |  |  |             try | 
 |  |  |             { | 
 |  |  |                 SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); | 
 |  |  |  | 
 |  |  |                 if (user == "10000")//api同步方式 | 
 |  |  |                 { | 
 |  |  |                     oCN.RunProc("delete from Gy_Material where HERPItemID=" + HItemID); | 
 |  |  | 
 |  |  |                     objJsonResult.data = null; | 
 |  |  |                     return objJsonResult; ; | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 //删除权限 | 
 |  |  |                 if (!DBUtility.ClsPub.Security_Log("Gy_Material_Delete", 1, false, user)) | 
 |  |  |                 { | 
 |  |  | 
 |  |  |                 ds = oCN.RunProcReturn("select * from Gy_Material where HItemID=" + HItemID, "Gy_Material"); | 
 |  |  |                 if (ds == null || ds.Tables[0].Rows.Count == 0) | 
 |  |  |                 { | 
 |  |  |                     oCN.RollBack();//回滚事务 | 
 |  |  |                     objJsonResult.code = "0"; | 
 |  |  |                     objJsonResult.count = 0; | 
 |  |  |                     objJsonResult.Message = "没有数据,无法删除!"; | 
 |  |  | 
 |  |  |             } | 
 |  |  |             catch (Exception e) | 
 |  |  |             { | 
 |  |  |                 oCN.RollBack();//回滚事务 | 
 |  |  |                 objJsonResult.code = "0"; | 
 |  |  |                 objJsonResult.count = 0; | 
 |  |  |                 objJsonResult.Message = "删除失败!" + e.ToString(); | 
 |  |  | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         #region 器具档案列表 树状图 设备分类查询 | 
 |  |  |         public class TreeModel | 
 |  |  |         { | 
 |  |  |             public string id { get; set; } | 
 |  |  |             public string title { get; set; } | 
 |  |  |             public List<TreeModel> children = new List<TreeModel>(); | 
 |  |  |         } | 
 |  |  |         [Route("Gy_Mould/TreeList")] | 
 |  |  |         [HttpGet] | 
 |  |  |         public object TreeList(string sWhere, string user) | 
 |  |  |         { | 
 |  |  |             try | 
 |  |  |             { | 
 |  |  |  | 
 |  |  |                 ds = oCN.RunProcReturn("select HItemID,HNumber,HName  from Gy_MouldType", "Gy_MouldType"); | 
 |  |  |  | 
 |  |  |                 List<TreeModel> treeModels = new List<TreeModel>(); | 
 |  |  |                 TreeModel first = new TreeModel(); | 
 |  |  |                 first.id = "0"; | 
 |  |  |                 first.title = "器具分类设置"; | 
 |  |  |                 treeModels.Add(first); | 
 |  |  |  | 
 |  |  |                 foreach (DataRow row in ds.Tables[0].Rows) | 
 |  |  |                 { | 
 |  |  |                     var strLen = row["hitemid"].ToString().Split('.'); | 
 |  |  |                     if (strLen.Length == 1) | 
 |  |  |                     { | 
 |  |  |                         TreeModel tree = new TreeModel(); | 
 |  |  |                         tree.id = row["HItemID"].ToString(); | 
 |  |  |                         tree.title = row["HName"].ToString(); | 
 |  |  |                         treeModels[0].children.Add(tree); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |                 digui(ds.Tables[0], treeModels[0].children, 2); | 
 |  |  |  | 
 |  |  |  | 
 |  |  |                 objJsonResult.code = "1"; | 
 |  |  |                 objJsonResult.count = 1; | 
 |  |  |                 objJsonResult.Message = "Sucess!"; | 
 |  |  |                 objJsonResult.data = Newtonsoft.Json.JsonConvert.SerializeObject(treeModels); | 
 |  |  |                 return objJsonResult; | 
 |  |  |             } | 
 |  |  |             catch (Exception e) | 
 |  |  |             { | 
 |  |  |                 objJsonResult.code = "0"; | 
 |  |  |                 objJsonResult.count = 0; | 
 |  |  |                 objJsonResult.Message = "Exception!" + e.ToString(); | 
 |  |  |                 objJsonResult.data = null; | 
 |  |  |                 return objJsonResult; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         /// <summary> | 
 |  |  |         /// 递归函数 | 
 |  |  |         /// </summary> | 
 |  |  |         public void digui(DataTable dt, List<TreeModel> tree, int num) | 
 |  |  |         { | 
 |  |  |             for (int m = 0; m < tree.Count; m++) | 
 |  |  |             { | 
 |  |  |                 tree[m].children = new List<TreeModel>(); | 
 |  |  |                 for (int i = 0; i < dt.Rows.Count; i++)//第一次循环,得到所有根节点的子集 | 
 |  |  |                 { | 
 |  |  |                     var strLen = dt.Rows[i]["HNumber"].ToString().Split('.'); | 
 |  |  |                     if (strLen.Length == num && dt.Rows[i]["HNumber"].ToString().Contains(tree[m].id + ".")) | 
 |  |  |                     { | 
 |  |  |                         TreeModel tbjson = new TreeModel(); | 
 |  |  |                         tbjson.id = dt.Rows[i]["HItemID"].ToString(); | 
 |  |  |                         tbjson.title = dt.Rows[i]["HName"].ToString(); | 
 |  |  |                         tree[m].children.Add(tbjson); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |                 var strLens = tree[m].id.Split('.'); | 
 |  |  |                 for (int i = 0; i < tree[m].children.Count; i++) | 
 |  |  |                 { | 
 |  |  |                     digui(dt, tree[m].children, strLens.Length + 2);//再次用子集去循环,拿出子集的子集 | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |         } | 
 |  |  |         #endregion | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  | 
 |  |  |             string HInterID = HInter.Replace("\"", ""); | 
 |  |  |             string user = sArray[1].ToString(); | 
 |  |  |             string HBarCode = sArray[2].ToString().Replace("\"",""); | 
 |  |  |             string HComputerName = SystemInformation.ComputerName; //设备名称 | 
 |  |  |  | 
 |  |  |             //编辑权限 | 
 |  |  |             if (!DBUtility.ClsPub.Security_Log("Gy_BarCodeBillList_Edit", 1, false, user)) | 
 |  |  |             { | 
 |  |  |                 objJsonResult.code = "0"; | 
 |  |  |                 objJsonResult.count = 0; | 
 |  |  |                 objJsonResult.Message = "无删除权限!"; | 
 |  |  |                 objJsonResult.data = null; | 
 |  |  |                 return objJsonResult; | 
 |  |  |             } | 
 |  |  |             string HComputerName = SystemInformation.ComputerName; //设备名称            | 
 |  |  |  | 
 |  |  |             try | 
 |  |  |             { | 
 |  |  | 
 |  |  |  | 
 |  |  |                 string[] NewBarCode; | 
 |  |  |                 NewBarCode = HBarCode.Split(Convert.ToChar(",")); | 
 |  |  |  | 
 |  |  |                 //编辑权限 | 
 |  |  |                 if (!DBUtility.ClsPub.Security_Log("Gy_BarCodeBill_Del", 1, false, user)) | 
 |  |  |                 { | 
 |  |  |                     objJsonResult.code = "0"; | 
 |  |  |                     objJsonResult.count = 0; | 
 |  |  |                     objJsonResult.Message = "无删除权限!"; | 
 |  |  |                     objJsonResult.data = null; | 
 |  |  |                     return objJsonResult; | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 //删除条码前进行判断 | 
 |  |  |                 Ds = oCN.RunProcReturn("exec h_p_Gy_BarCodeBill_MulDelete_Before '" + HInterID + "','" + HBarCode + "'", "h_p_Gy_BarCodeBill_MulDelete_Before", ref DBUtility.ClsPub.sExeReturnInfo); | 
 |  |  | 
 |  |  |                 if (Ds.Tables[0].Rows.Count != 0) | 
 |  |  |                 { | 
 |  |  |                     oCN.BeginTran(); | 
 |  |  |                     oCN.RunProc("Delete from Gy_BarCodeBill Where HItemID in (" + HInterID + ")"); | 
 |  |  |  | 
 |  |  |                     //获取系统参数 | 
 |  |  |                     string Ret = ""; | 
 |  |  |                     if (oSystemParameter.ShowBill(ref Ret)) | 
 |  |  |                     { | 
 |  |  |                         //判断是否只能删除自己生成的条码 | 
 |  |  |                         if (oSystemParameter.omodel.BarCode_DeleterAndMakerMustSame == "Y") //系统参数                       | 
 |  |  |                         { | 
 |  |  |                             oCN.RunProc("Delete from Gy_BarCodeBill Where HItemID in (" + HInterID + ")" + " and HMaker = '" + user + "'"); | 
 |  |  |                         } | 
 |  |  |                         else | 
 |  |  |                         { | 
 |  |  |                             oCN.RunProc("Delete from Gy_BarCodeBill Where HItemID in (" + HInterID + ")"); | 
 |  |  |                         } | 
 |  |  |                     }                     | 
 |  |  |  | 
 |  |  |                     //写入系统日志 | 
 |  |  |                     for (int i = 0; i <= NewBarCode.Length - 1; i++) | 
 |  |  | 
 |  |  |                 int HMouldMaintainRuleInterID = mainList[0].HMouldMaintainRuleInterID; | 
 |  |  |                 int HNowSupID = mainList[0].HNowSupID; | 
 |  |  |                 int HNowSupTypeID = mainList[0].HNowSupTypeID; | 
 |  |  |  | 
 |  |  |                 int HMadeSupID = mainList[0].HMadeSupID; | 
 |  |  |                 string HMouldClass = mainList[0].HMouldClass; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |                 //主表 | 
 |  |  | 
 |  |  |                 ",HOutComDate,HOutComNo,HDeptID,HSupID,HSupNumber" + | 
 |  |  |                 ",HPrintQty,HMouldStatus,HWhID,HRoutingID,HCaveQty" + | 
 |  |  |                 ",HBomID,HVersion,HSPGroupID,HSPID,HDesignLife,HNowSupID,HNowSupTypeID" + | 
 |  |  |                 ",HUseLife,HLeaveLife,HProdQty,HProdWeight,HMouldOWNER,HSaveLife,HMouldDotCheckRuleInterID,HMouldMaintainRuleInterID,HBarCode" + | 
 |  |  |                 ") " + | 
 |  |  |                 ",HUseLife,HLeaveLife,HProdQty,HProdWeight,HMouldOWNER,HSaveLife,HMouldDotCheckRuleInterID,HMouldMaintainRuleInterID,HBarCode,HMadeSupID" + | 
 |  |  |                 ",HMouldClass) " + | 
 |  |  |                 " values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "','" + HDate + "'" + | 
 |  |  |                 "," + HYear + "," + HPeriod + ",'" + HRemark + "','" + HMaker + "',getdate()" + | 
 |  |  |                 ",'" + HMouldNo + "','" + HName + "','" + HModel + "','" + HModel2 + "','" + HDiameter + "'" + | 
 |  |  | 
 |  |  |                 ",'" + HOutComDate + "','" + HOutComNo + "'," + HDeptID + "," + HSupID + ",'" + HSupNumber + "'" + | 
 |  |  |                 "," + HPrintQty + ",'" + HMouldStatus + "'," + HWHID + "," + HRoutingID + "," + HCaveQty + | 
 |  |  |                 "," + HBOMID + ",'" + HVersion + "'," + HSPGroupID + "," + HSPID + ",'" + HDesignLife + "','" + HNowSupID + "','" + HNowSupTypeID + "'" + | 
 |  |  |                 ",'" + HUseLife + "','" + HLeaveLife + "','" + HProdQty + "','" + HProdWeight + "','" + HMouldOWNER + "','" + HSaveLife + "','" + HMouldDotCheckRuleInterID + "','" + HMouldMaintainRuleInterID + "','" + HBarCode + "'" + | 
 |  |  |                 ") "); | 
 |  |  |                 ",'" + HUseLife + "','" + HLeaveLife + "','" + HProdQty + "','" + HProdWeight + "','" + HMouldOWNER + "','" + HSaveLife + "','" + HMouldDotCheckRuleInterID + "','" + HMouldMaintainRuleInterID + "','" + HBarCode + "'," + HMadeSupID + | 
 |  |  |                 ",'"+ HMouldClass + "') "); | 
 |  |  |  | 
 |  |  |  | 
 |  |  |                 //子表 | 
 |  |  | 
 |  |  |                 int HMouldMaintainRuleInterID = mainList[0].HMouldMaintainRuleInterID; | 
 |  |  |                 int HNowSupID = mainList[0].HNowSupID; | 
 |  |  |                 int HNowSupTypeID = mainList[0].HNowSupTypeID; | 
 |  |  |                 int HMadeSupID = mainList[0].HMadeSupID; | 
 |  |  |                 string HMouldClass = mainList[0].HMouldClass; | 
 |  |  |  | 
 |  |  |                 //若MAINDI重复则重新获取 | 
 |  |  |                 oCN.BeginTran(); | 
 |  |  | 
 |  |  |                 ",HWorkMaterModel='" + HWorkMaterModel + "'" + | 
 |  |  |                 ",HMaterID=" + HMaterID.ToString() + | 
 |  |  |                 ",HMaterNumber='" + HMaterNumber + "'" + | 
 |  |  |                 ",HMouldClass='" + HMouldClass + "'" + | 
 |  |  |                 ",HMouldType=" + HMouleTypeID.ToString() + | 
 |  |  |                 ",HUnitID=" + HUnitID.ToString() + | 
 |  |  |                 ",HOutComDate='" + HOutComDate + "'" + | 
 |  |  | 
 |  |  |                 ",HNowSupTypeID=" + HNowSupTypeID.ToString() + | 
 |  |  |                 ",HProdWeight=" + HProdWeight.ToString() + | 
 |  |  |                 ",HBarCode='" + HBarCode.ToString() + "'" + | 
 |  |  |                 ",HMadeSupID=" + HMadeSupID + | 
 |  |  |                 " where HInterID=" + HInterID.ToString()); | 
 |  |  |  | 
 |  |  |                 //修改子项目代码 | 
 |  |  | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         /// <summary> | 
 |  |  |         /// 磨具档案修改按钮方法-计算下次保养/校正日期-获取档案最近一次的保养记录 | 
 |  |  |         ///参数:string sql。 | 
 |  |  |         ///返回值:object。 | 
 |  |  |         /// </summary> | 
 |  |  |         [Route("Gy_Mould_Edit/calculateHNextMainDate")] | 
 |  |  |         [HttpGet] | 
 |  |  |         public object calculateHNextMainDate(long HInterID) | 
 |  |  |         { | 
 |  |  |             try | 
 |  |  |             { | 
 |  |  |                 string sql = @"select top(1) a.HInterID, b.HEndDate 保养记录结束日期 | 
 |  |  |                             from Gy_MouldFileMain AS a LEFT OUTER JOIN | 
 |  |  |                             Sc_MouldMaintainBillMain AS b on a.HInterID = b.HMouldID | 
 |  |  |                             where a.HInterID = " + HInterID + | 
 |  |  |                             " order by b.HEndDate desc"; | 
 |  |  |  | 
 |  |  |                 ds = oCN.RunProcReturn(sql, "Sc_MouldMaintainBillMain"); | 
 |  |  |  | 
 |  |  |                 objJsonResult.code = "1"; | 
 |  |  |                 objJsonResult.count = 1; | 
 |  |  |                 objJsonResult.Message = ""; | 
 |  |  |                 objJsonResult.data = ds.Tables[0]; | 
 |  |  |                 return objJsonResult; | 
 |  |  |             } | 
 |  |  |             catch (Exception e) | 
 |  |  |             { | 
 |  |  |                 objJsonResult.code = "0"; | 
 |  |  |                 objJsonResult.count = 0; | 
 |  |  |                 objJsonResult.Message = "Exception!" + e.ToString(); | 
 |  |  |                 objJsonResult.data = null; | 
 |  |  |                 return objJsonResult; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         /// <summary> | 
 |  |  |         /// 磨具档案修改按钮方法 | 
 |  |  | 
 |  |  |             public string msg { get; set; }   //末级标志 | 
 |  |  |  | 
 |  |  |         } | 
 |  |  |         #region  物料文件上传处理 | 
 |  |  |         [Route("Gy_Mater/UploadFile")] | 
 |  |  |         [HttpPost] | 
 |  |  |         public object UploadFile() | 
 |  |  |         { | 
 |  |  |  | 
 |  |  |             string HNumber = HttpContext.Current.Request.Params["HNumber"];  //物料代码 | 
 |  |  |             string HRemark = HttpContext.Current.Request.Params["HRemark"];  //备注 | 
 |  |  |             string HUserName = HttpContext.Current.Request.Params["HUserName"];  //创建人 | 
 |  |  |             HttpPostedFile files = HttpContext.Current.Request.Files["file"]; | 
 |  |  |             string path = HttpContext.Current.Server.MapPath("~/../Files/Material/" + HNumber); | 
 |  |  |             //string path = @"D:\\Files\Material\\"+ HBillNo; | 
 |  |  |             dynamic dyResult = UpLoadFile(files, path, HNumber, HRemark, HUserName); | 
 |  |  |             if (dyResult != null && dyResult.result == 1) | 
 |  |  |             { | 
 |  |  |                 objJsonResult.code = "1"; | 
 |  |  |                 objJsonResult.count = 1; | 
 |  |  |                 objJsonResult.Message = "上传成功!"; | 
 |  |  |                 objJsonResult.data = null; | 
 |  |  |                 return objJsonResult; | 
 |  |  |             } | 
 |  |  |             else | 
 |  |  |             { | 
 |  |  |                 objJsonResult.code = "0"; | 
 |  |  |                 objJsonResult.count = 0; | 
 |  |  |                 objJsonResult.Message = dyResult.returnval; | 
 |  |  |                 objJsonResult.data = null; | 
 |  |  |                 return objJsonResult; | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         public dynamic UpLoadFile(HttpPostedFile files, string path, string HNumber, string HRemark, string HUserName) | 
 |  |  |         { | 
 |  |  |             dynamic Result_Ob = new { result = 1, returnval = "上传成功!" }; | 
 |  |  |             string filePath = Path.GetFullPath(files.FileName);//文件上传路径 | 
 |  |  |             string fileExtension = Path.GetExtension(files.FileName);// 文件扩展名 | 
 |  |  |             string filename = files.FileName;//文件名 | 
 |  |  |             string fileSavePath = path;// 上传保存路径 | 
 |  |  |             int filesize = files.ContentLength;//获取上传文件的大小单位为字节byte | 
 |  |  |             int Maxsize = 40000 * 1024;//定义上传文件的最大空间大小为40M | 
 |  |  |             try | 
 |  |  |             { | 
 |  |  |                 if (files == null || files.ContentLength <= 0) | 
 |  |  |                 { | 
 |  |  |                     Result_Ob = new { result = 0, returnval = "文件不能为空!" }; | 
 |  |  |                     return Result_Ob; | 
 |  |  |                 } | 
 |  |  |                 if (filesize >= Maxsize) | 
 |  |  |                 { | 
 |  |  |                     Result_Ob = new { result = 0, returnval = "上传文件超过40M,不能上传!" }; | 
 |  |  |                     return Result_Ob; | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 string fileurl = Path.Combine(fileSavePath, filename); | 
 |  |  |                 if (Directory.Exists(fileurl) == true)  //如果存在重名文件就提示   | 
 |  |  |                 { | 
 |  |  |                     Result_Ob = new { result = 0, returnval = "存在同名文件!" }; | 
 |  |  |                     return Result_Ob; | 
 |  |  |                 } | 
 |  |  |                 //删除数据表数据 | 
 |  |  |                 ds = oCN.RunProcReturn("delete from MES_AccessoriesList where HSourceBillNo ='" + HNumber + "' and HFileName='" + filename + "'", "MES_AccessoriesList"); | 
 |  |  |                 if (Directory.Exists(path)) | 
 |  |  |                 { | 
 |  |  |                     File.Delete(fileurl);      //删除指定文件 | 
 |  |  |                     files.SaveAs(fileurl); | 
 |  |  |                     string StrPath = "/files/Material/" + HNumber + "/" + filename; | 
 |  |  |                     if (File.Exists(fileurl)) | 
 |  |  |                     { | 
 |  |  |                         //这里可以执行一些其它的操作,比如更新数据库 | 
 |  |  |                         //写入数据表 | 
 |  |  |                         oCN.RunProc("Insert into MES_AccessoriesList (HFileName,HFilePath,HFilePath_Cus,HFileType" + | 
 |  |  |                                     ",HLoadMan,HLoadDate,HRemark,HVerNum,HFileSize" + | 
 |  |  |                                     ",HFileClsID,HSourceBillNo" + | 
 |  |  |                                    ") values('" | 
 |  |  |                                     + filename.ToString() + "','" + StrPath.ToString() + "','" + filePath.ToString() + "','" + fileExtension.ToString() + "'" + | 
 |  |  |                                     ",'" + HUserName + "',getdate(),'" + HRemark + "','V1','" + filesize + | 
 |  |  |                                     "','" + 0 + "','" + HNumber + | 
 |  |  |                                    "') "); | 
 |  |  |                     } | 
 |  |  |                     else | 
 |  |  |                     { | 
 |  |  |                         Result_Ob = new { result = 0, returnval = "上传失败!此文件为恶意文件" }; | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |                 else | 
 |  |  |                 { | 
 |  |  |                     Directory.CreateDirectory(fileSavePath); //添加文件夹 | 
 |  |  |                     files.SaveAs(fileurl); | 
 |  |  |                     string StrPath = "/files/Material/" + HNumber + "/" + filename; | 
 |  |  |                     if (File.Exists(fileurl)) | 
 |  |  |                     { | 
 |  |  |                         //这里可以执行一些其它的操作,比如更新数据库 | 
 |  |  |                         //写入数据表 | 
 |  |  |                         oCN.RunProc("Insert into MES_AccessoriesList (HFileName,HFilePath,HFilePath_Cus,HFileType" + | 
 |  |  |                                     ",HLoadMan,HLoadDate,HRemark,HVerNum,HFileSize" + | 
 |  |  |                                     ",HFileClsID,HSourceBillNo" + | 
 |  |  |                                    ") values('" | 
 |  |  |                                     + filename.ToString() + "','" + StrPath.ToString() + "','" + filePath.ToString() + "','" + fileExtension.ToString() + "'" + | 
 |  |  |                                     ",'" + HUserName + "',getdate(),'" + HRemark + "','V1','" + filesize + | 
 |  |  |                                     "','" + 0 + "','" + HNumber + | 
 |  |  |                                    "') "); | 
 |  |  |                     } | 
 |  |  |                     else | 
 |  |  |                     { | 
 |  |  |                         Result_Ob = new { result = 0, returnval = "上传失败!此文件为恶意文件" }; | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |             } | 
 |  |  |             catch (Exception e) | 
 |  |  |             { | 
 |  |  |                 Result_Ob = new { result = 0, returnval = e.Message }; | 
 |  |  |             } | 
 |  |  |             return Result_Ob; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         /// <summary> | 
 |  |  |         /// 根据单据号查找上传文件列表 | 
 |  |  |         /// </summary> | 
 |  |  |         /// <param name="sWhere"></param> | 
 |  |  |         /// <returns></returns> | 
 |  |  |         [Route("Gy_Mater/Filelist")] | 
 |  |  |         [HttpGet] | 
 |  |  |         public object Filelist(string HNumber) | 
 |  |  |         { | 
 |  |  |             var url = fileip + "/files/Material/" + HNumber + "/"; | 
 |  |  |             //@"C:\\files\\" | 
 |  |  |             try | 
 |  |  |             { | 
 |  |  |                 ds = oCN.RunProcReturn("select *,'" + url + "'+CAST(HFileName as varchar(200))as url  from MES_AccessoriesList where HSourceBillNo='" + HNumber + "'", "MES_AccessoriesList"); | 
 |  |  |                 objJsonResult.code = "1"; | 
 |  |  |                 objJsonResult.count = 1; | 
 |  |  |                 objJsonResult.Message = "Sucess!"; | 
 |  |  |                 objJsonResult.data = ds.Tables[0]; | 
 |  |  |                 return objJsonResult; | 
 |  |  |  | 
 |  |  |             } | 
 |  |  |             catch (Exception e) | 
 |  |  |             { | 
 |  |  |                 objJsonResult.code = "0"; | 
 |  |  |                 objJsonResult.count = 0; | 
 |  |  |                 objJsonResult.Message = "Exception!" + e.ToString(); | 
 |  |  |                 objJsonResult.data = null; | 
 |  |  |                 return objJsonResult; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         /// <summary> | 
 |  |  |         /// 根据ID,单据号,文件名 删除文件 | 
 |  |  |         /// </summary> | 
 |  |  |         /// <param name="sWhere"></param> | 
 |  |  |         /// <returns></returns> | 
 |  |  |         [Route("Gy_Mater/DeleteFilelist")] | 
 |  |  |         [HttpGet] | 
 |  |  |         public object DeleteFilelist(string HItemID, string HSourceBillNo, string HFileName) | 
 |  |  |         { | 
 |  |  |             try | 
 |  |  |             { | 
 |  |  |  | 
 |  |  |                 oCN.RunProc("delete from MES_AccessoriesList where HItemID =" + HItemID); | 
 |  |  |                 string fileurl = Path.Combine(HttpContext.Current.Server.MapPath("~/../Files/Material/" + HSourceBillNo), HFileName); | 
 |  |  |                 File.Delete(fileurl);      //删除指定文件 | 
 |  |  |                 objJsonResult.code = "1"; | 
 |  |  |                 objJsonResult.count = 1; | 
 |  |  |                 objJsonResult.Message = "删除成功!"; | 
 |  |  |                 objJsonResult.data = null; | 
 |  |  |                 return objJsonResult; | 
 |  |  |             } | 
 |  |  |             catch (Exception e) | 
 |  |  |             { | 
 |  |  |                 objJsonResult.code = "0"; | 
 |  |  |                 objJsonResult.count = 0; | 
 |  |  |                 objJsonResult.Message = "Exception!" + e.ToString(); | 
 |  |  |                 objJsonResult.data = null; | 
 |  |  |                 return objJsonResult; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         #endregion | 
 |  |  |  | 
 |  |  |     } | 
 |  |  | } |