1
yusijie
2023-03-09 85c65fb1370c15be6094b378dd42f96ea012996a
WebAPI/Controllers/CJGL/Cj_StationOutBillController.cs
@@ -437,6 +437,7 @@
                string msg2 = sArray[0].ToString();
                string msg3 = sArray[1].ToString();
                string msg4 = sArray[2].ToString();
                string msg5 = sArray[3].ToString();
                List<Model.ClsSc_StationOutBillMain> list = new List<Model.ClsSc_StationOutBillMain>();
                
@@ -454,8 +455,8 @@
                    oBill.omodel.HBillNo = msg3 + "- " + j;
                    oBill.omodel.HBillStatus = 0;
                    oBill.omodel.HMouldNum = list[i].HMouldNum;
                    oBill.omodel.HYear = 2022;
                    oBill.omodel.HPeriod = 1;
                    oBill.omodel.HYear = DateTime.Now.Year;
                    oBill.omodel.HPeriod = DateTime.Now.Month;
                    oBill.omodel.HRemark = list[i].HRemark;
                    oBill.omodel.HSourceName = list[i].HSourceName;
                    oBill.omodel.HPieceQty = list[i].HPieceQty;
@@ -508,6 +509,7 @@
                    oBill.omodel.HWorkTimes = list[i].HWorkTimes;
                    oBill.omodel.HQCCheckID = list[i].HQCCheckID;
                    oBill.omodel.HMaker = msg4;
                    oBill.omodel.HEmpNum = msg5;
                    //string HBillSubType = "3791";
                    //long HInterID = list[0].HInterID;//递入type得到的单据ID
@@ -923,6 +925,126 @@
            return Result_Ob;
        }
        [Route("Cj_StationOutBill/UploadFile2")]
        [HttpPost]
        public object UploadFile2()
        {
            string HBillNo = HttpContext.Current.Request.Params["HBillNo"];  //单据号
            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/" + HBillNo);
            //string path = @"D:\\Files\\"+ HBillNo;
            dynamic dyResult = UpLoadFile1(files, path, HBillNo, 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 UpLoadFile1(HttpPostedFile files, string path, string HBillNo, 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 ='" + HBillNo + "' and HFileName='" + filename + "'", "MES_AccessoriesList");
                if (Directory.Exists(path))
                {
                    File.Delete(fileurl);      //删除指定文件
                    files.SaveAs(fileurl);
                    string StrPath = "/files/" + HBillNo + "/" + 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 + "','" + HBillNo +
                                   "') ");
                    }
                    else
                    {
                        Result_Ob = new { result = 0, returnval = "上传失败!此文件为恶意文件" };
                    }
                }
                else
                {
                    Directory.CreateDirectory(fileSavePath); //添加文件夹
                    files.SaveAs(fileurl);
                    string StrPath = "/files/" + HBillNo + "/" + 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() + "','" + fileurl.ToString() + "','" + filePath.ToString() + "','" + fileExtension.ToString() + "'" +
                                    ",'" + HUserName + "',getdate(),'" + HRemark + "','V1','" + filesize +
                                    "','" + 0 + "','" + HBillNo +
                                   "') ");
                    }
                    else
                    {
                        Result_Ob = new { result = 0, returnval = "上传失败!此文件为恶意文件" };
                    }
                }
            }
            catch (Exception e)
            {
                Result_Ob = new { result = 0, returnval = e.Message };
            }
            return Result_Ob;
        }
        /// <summary>
        /// 输出json结果 返回2个值 result (输出succes的值)   returnval (输出str的值)
        /// </summary>
@@ -1098,6 +1220,72 @@
        }
        #endregion
        #region 根据单据号 同步报错删除出站单
        [Route("Cj_StationOutBill/DelStationOutBill")]
        [HttpGet]
        public object DelStationOutBill(string HInterID)
        {
            try
            {
                DAL.ClsSc_StationOutBill oBill = new DAL.ClsSc_StationOutBill();
                SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                DataTable DTable;
                int num = 0;
                //判断入库是否同步
                 DTable = oCN.RunProcReturn("select * from  Sc_StationOutBillMain where HInterID='" + HInterID + "' and  HRelationQty=0", "Sc_StationOutBillMain").Tables[0];
                if (DTable.Rows.Count != 0)
                {
                    num++;
                }
                //判断本次报废是否同步
                DTable = oCN.RunProcReturn("select * from  Sc_StationOutBillMain where  HProcExchInterID='" + DTable.Rows[0]["HProcExchInterID"].ToString() + "' and HBFFlag=0 ", "Sc_StationOutBillMain").Tables[0];
                if (DTable.Rows.Count != 0)
                {
                    num++;
                }
                if (num == 2)
                {
                    if (!oBill.DeleteBill(long.Parse(HInterID), 0, 0, ref DBUtility.ClsPub.sExeReturnInfo))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = DBUtility.ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    else
                    {
                        objJsonResult.code = "1";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "删除成功!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "无须删除!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "异常!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 编辑前判断
        [Route("Cj_StationOutBill/set_ShowBillJudge")]
        [HttpGet]