wangyi
1 天以前 aca2ad77dd242fb9fe223b6cc30bbcf69e9a6eab
WebAPI/Controllers/CGGL/Kf_POStockInBillController.cs
@@ -1,6 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NPOI.SS.Formula.Functions;
using Pub_Class;
using System;
using System.Collections;
@@ -9,6 +8,7 @@
using System.Data.SqlClient;
using System.Web.Http;
using WebAPI.Models;
using System.Windows.Forms;
using SyntacticSugar.constant;
namespace WebAPI.Controllers
@@ -617,6 +617,102 @@
            }
        }
        #endregion
        #region 采购入库单 - 托数变更功能
        [Route("Kf_POStockInBill/UpdatePallet")]
        [HttpPost]
        public object UpdatePallet([FromBody] JObject data)
        {
            try
            {
                long hmainid = data["hmainid"]?.ToObject<long>() ?? 0;
                int newPallet = data["newPallet"]?.ToObject<int>() ?? 0;
                string operatorName = data["operator"]?.ToString() ?? "";
                if (hmainid <= 0)
                    return new { code = "0", count = 0, Message = "单据ID不能为空!" };
                if (newPallet < 0)
                    return new { code = "0", count = 0, Message = "托数不能为负数!" };
                // 直接更新托数
                string updateSql = $@"
                    UPDATE  Kf_ICStockBillMain
                    SET HPackQtys = {newPallet}
                    WHERE HInterID = {hmainid}";
                oCN.RunProc(updateSql);
                return new
                {
                    code = "1",
                    count = 1,
                    Message = "托数修改成功!"
                };
            }
            catch (Exception e)
            {
                return new
                {
                    code = "0",
                    count = 0,
                    Message = "修改失败:" + e.Message
                };
            }
        }
        #endregion
        #region 采购入库单 - 贴标签数变更功能
        [Route("Kf_POStockInBill/UpdateHTagCount")]
        [HttpPost]
        public object UpdateHTagCount([FromBody] JObject data)
        {
            try
            {
                long hmainid = data["hmainid"]?.ToObject<long>() ?? 0;
                int newPallet = data["newPallet"]?.ToObject<int>() ?? 0;
                string operatorName = data["operator"]?.ToString() ?? "";
                if (hmainid <= 0)
                    return new { code = "0", count = 0, Message = "单据ID不能为空!" };
                if (newPallet <= 0)
                    return new { code = "0", count = 0, Message = "贴标签数必须大于0!" };
                // 直接更新托数
                string updateSql = $@"
                    UPDATE  Kf_ICStockBillMain
                    SET HTagCount = {newPallet}
                    WHERE HInterID = {hmainid}";
                oCN.RunProc(updateSql);
                return new
                {
                    code = "1",
                    count = 1,
                    Message = "托数修改成功!"
                };
            }
            catch (Exception e)
            {
                return new
                {
                    code = "0",
                    count = 0,
                    Message = "修改失败:" + e.Message
                };
            }
        }
        #endregion
        #region 查找记录功能
        /// <summary>
@@ -2115,39 +2211,39 @@
                List<ClsKf_ICStockBillSub> subList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsKf_ICStockBillSub>>(entry);
                // 判断 数据库中是否存在id和单据号相等的单据,存在,则重建,只有id号相等,则申请新的id号
                // var ds1 = oCN.RunProcReturn($@"
                // select hmainid HInterID, 单据号 HBillNO from h_v_Kf_POStockInBillList where hmainid = {mainList[0].HInterID}
                // ", "h_v_Kf_POStockInBillList");
                // var HInterID_Old = mainList[0].HInterID;
                // if (ds1.Tables[0].Rows.Count > 0 && ds1.Tables[0].Rows[0]["HInterID"] != null)
                // {
                //     if (string.Equals(ds1.Tables[0].Rows[0]["HBillNo"].ToString(), mainList[0].HBillNo, StringComparison.OrdinalIgnoreCase))
                //     {
                //         string sql = string.Empty;
                //         sql = $"delete Kf_ICStockBillMain where HinterID = {mainList[0].HInterID}";
                //         oCN.RunProc(sql);
                //         sql = $"delete Kf_ICStockBillSub where HinterID = {mainList[0].HInterID}";
                //         oCN.RunProc(sql);
                //     }
                //     else
                //     {
                //         // 重新申请HInterID
                //         var HInterID_Exch = DBUtility.ClsPub.CreateBillID("1201", ref DBUtility.ClsPub.sExeReturnInfo);
                //         mainList[0].HInterID = HInterID_Exch;
                //
                //         foreach (var oSub in subList)
                //         {
                //             oSub.HInterID = HInterID_Exch;
                //         }
                //
                //     }
                // }
                var ds1 = oCN.RunProcReturn($@"
                select hmainid HInterID, 单据号 HBillNO from h_v_Kf_POStockInBillList where hmainid = {mainList[0].HInterID}
                ", "h_v_Kf_POStockInBillList");
                var HInterID_Old = mainList[0].HInterID;
                if (ds1.Tables[0].Rows.Count > 0 && ds1.Tables[0].Rows[0]["HInterID"] != null)
                {
                    if (string.Equals(ds1.Tables[0].Rows[0]["HBillNo"].ToString(), mainList[0].HBillNo, StringComparison.OrdinalIgnoreCase))
                    {
                        string sql = string.Empty;
                        sql = $"delete Kf_ICStockBillMain where HinterID = {mainList[0].HInterID}";
                        oCN.RunProc(sql);
                        sql = $"delete Kf_ICStockBillSub where HinterID = {mainList[0].HInterID}";
                        oCN.RunProc(sql);
                    }
                    else
                    {
                        // 重新申请HInterID
                        var HInterID_Exch = DBUtility.ClsPub.CreateBillID("1201", ref DBUtility.ClsPub.sExeReturnInfo);
                        mainList[0].HInterID = HInterID_Exch;
                        foreach (var oSub in subList)
                        {
                            oSub.HInterID = HInterID_Exch;
                        }
                    }
                }
                string sql = string.Empty;
                sql = $"delete Kf_ICStockBillMain where HinterID = {mainList[0].HInterID}";
                oCN.RunProc(sql);
                sql = $"delete Kf_ICStockBillSub where HinterID = {mainList[0].HInterID}";
                oCN.RunProc(sql);
                // string sql = string.Empty;
                // sql = $"delete Kf_ICStockBillMain where HinterID = {mainList[0].HInterID}";
                // oCN.RunProc(sql);
                // sql = $"delete Kf_ICStockBillSub where HinterID = {mainList[0].HInterID}";
                // oCN.RunProc(sql);
                // 主表插入
                oCN.RunProc($@"Insert Into Kf_ICStockBillMain 
                (