From 4548e24916ac5f63eef736cabdcd634864f8de16 Mon Sep 17 00:00:00 2001 From: wangbin <lan@DESKTOP-MG88OFJ> Date: 星期一, 08 七月 2024 10:39:16 +0800 Subject: [PATCH] 1 --- WebAPI/Controllers/BLL/Xt_AccountPeriodController.cs | 177 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 167 insertions(+), 10 deletions(-) diff --git a/WebAPI/Controllers/BLL/Xt_AccountPeriodController.cs b/WebAPI/Controllers/BLL/Xt_AccountPeriodController.cs index 0d11ad3..00cbd97 100644 --- a/WebAPI/Controllers/BLL/Xt_AccountPeriodController.cs +++ b/WebAPI/Controllers/BLL/Xt_AccountPeriodController.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Data; using System.Data.SqlClient; +using System.Globalization; using System.Web.Http; using WebAPI.Models; namespace WebAPI.Controllers @@ -166,7 +167,7 @@ long HPeriod = list[0].HPeriod; DateTime HBeginDate = list[0].HBeginDate; DateTime HEndDate = list[0].HEndDate; - string HEndFlag = list[0].HEndFlag; + string HEndFlag = "1"; @@ -181,14 +182,14 @@ "(HYear,HPeriod,HBeginDate,HEndDate" + ",HEndFlag" + ") " + - " values(" + HYear + "," + HPeriod + "," + HBeginDate + "," + HEndDate + - ",'" + HEndFlag + "'" + + " values('" + HYear + "','" + HPeriod + "','" + HBeginDate + "','" + HEndDate + + "','" + HEndFlag + "'" + ") "); //淇敼涓婄骇涓洪潪鏈骇浠g爜 oCN.Commit(); objJsonResult.code = "1"; objJsonResult.count = 1; - objJsonResult.Message = "鏂板鍗曟嵁鎴愬姛锛�"; + objJsonResult.Message = "缁撹处鎴愬姛锛�"; //objJsonResult.data = null; return objJsonResult; } @@ -204,24 +205,32 @@ } /// <summary> - /// 浼氳鏈熼棿鍒楄〃鍒犻櫎鎸夐挳 + /// 浼氳鏈熼棿鍒楄〃鍙嶇粨璐︽寜閽� ///鍙傛暟锛歴tring sql銆� ///杩斿洖鍊硷細object銆� /// </summary> - [Route("Xt_AccountPeriod/Delete_Json")] + [Route("Xt_AccountPeriod/Update_Json")] [HttpGet] - public object Delete_Json(long HYaer,long HPeriod) + public object Update_Json(long HYear, long HPeriod ,string num) { try { //鑻AINDI閲嶅鍒欓噸鏂拌幏鍙� oCN.BeginTran(); + if (num=="1")//缁撹处 + { + oCN.RunProc("update Xt_AccountPeriod set HEndFlag=1 Where HYear =" + HYear + " and HPeriod=" + HPeriod, ref DBUtility.ClsPub.sExeReturnInfo); + } + else//鍙嶇粨璐� + { + oCN.RunProc("update Xt_AccountPeriod set HEndFlag=0 Where HYear =" + HYear + " and HPeriod=" + HPeriod, ref DBUtility.ClsPub.sExeReturnInfo); + } //涓昏〃 - oCN.RunProc("delete from Xt_AccountPeriod Where HYaer =" + HYaer + " and HPeriod=" + HPeriod, ref DBUtility.ClsPub.sExeReturnInfo); + oCN.Commit(); objJsonResult.code = "1"; objJsonResult.count = 1; - objJsonResult.Message = "鍒犻櫎鍗曟嵁鎴愬姛锛�"; + objJsonResult.Message = "鍙嶇粨璐︽垚鍔燂紒"; //objJsonResult.data = null; return objJsonResult; } @@ -235,6 +244,154 @@ } } - // + + /// <summary> + /// 缁撹处鑾峰彇鏈�鍚庝竴娆$粨璐︽椂闂� + /// </summary> + /// <param name="sWhere"></param> + /// <returns></returns> + [Route("Xt_AccountPeriod/Lastlist")] + [HttpGet] + public object Lastlist() + { + try + { + //褰搇astYear=2024 lastPeriod=1鏄�,瑕佽幏鍙栦笂骞存渶鍚庝竴鏈堢殑鏃堕棿 fistYear fistPeriod + string lastYear = ""; + string lastPeriod = ""; + string fistYear = ""; + string fistPeriod = ""; + List<object> columnNameList = new List<object>(); + + ds = oCN.RunProcReturn("select top 1 * from h_v_Xt_AccountPeriodList where 鏄惁缁撹处 = '鏄�' Order by 寮�濮嬫棩鏈� DESC", "h_v_Xt_AccountPeriodList"); + + //鑾峰彇瑕佺粨璐︾殑骞存湀 + if (ds.Tables[0].Rows[0]["浼氳鏈堜唤"].ToString()=="1") + { + fistYear = (Int64.Parse(ds.Tables[0].Rows[0]["浼氳骞翠唤"].ToString()) - 1).ToString(); + fistPeriod = (Int64.Parse(ds.Tables[0].Rows[0]["浼氳鏈堜唤"].ToString()) + 11).ToString(); + } + else + { + lastYear = ds.Tables[0].Rows[0]["浼氳骞翠唤"].ToString(); + lastPeriod = ds.Tables[0].Rows[0]["浼氳鏈堜唤"].ToString(); + } + + DateTime lastEndDate = (DateTime)ds.Tables[0].Rows[0]["缁撴潫鏃ユ湡"]; + + // 璁$畻瑕佺粨璐︾殑淇℃伅 + DateTime nextBeginDate = lastEndDate.AddDays(1); + DateTime nextEndDate = nextBeginDate.AddMonths(1).AddDays(-1); + + ds = oCN.RunProcReturn("select COUNT(*) 鏈鏍� from Kf_ICStockBillMain where HChecker ='' and HDate >='" + nextBeginDate + "' and HDate <='" + nextEndDate + "' ", "Kf_ICStockBillMain"); + if (ds.Tables[0].Rows[0]["鏈鏍�"].ToString() == "0") + { + if (fistYear=="") + { + //鏌ヨ涓婃湀姣忎釜浠撳簱,浠撲綅,鐗╂枡鎵�鏁伴噺澶氬皯,鏍规嵁涓婃湀鏁伴噺+鏈湀杩涘叆鏀嚭鏁伴噺,鎻掑叆鏈熷垵搴撳瓨琛� + string sql = "SELECT b.HWHID AS 浠撳簱, b.HSPID AS 浠撲綅,b.HMaterID AS 鐗╂枡," + + "SUM(CASE WHEN a.HYear = '" + lastYear + "' AND a.HPeriod = '" + lastPeriod + "' THEN b.HQty ELSE 0 END) AS 鏈熷垵," + + "SUM(CASE WHEN a.HYear = '" + lastYear + "' AND a.HPeriod = '" + lastPeriod + "' THEN b.HQty ELSE 0 END) AS 鏈湡, " + + "SUM(CASE WHEN a.HYear = '" + lastYear + "' AND (a.HPeriod = '" + lastPeriod + "' OR a.HPeriod = '" + lastPeriod + "') THEN b.HQty ELSE 0 END) AS 鎬昏 " + + "FROM Kf_ICStockBillMain a INNER JOIN Kf_ICStockBillSub b ON a.HInterID = b.HInterID WHERE a.HYear = '" + lastYear + "' AND (a.HPeriod = '" + lastPeriod + "' OR a.HPeriod = '" + lastPeriod + "') " + + "GROUP BY b.HWHID,b.HSPID,b.HMaterID ORDER BY b.HWHID,b.HSPID,b.HMaterID"; + ds = oCN.RunProcReturn(sql, "Kf_ICStockBillMain"); + + DataTable dt = ds.Tables[0]; + List<Kf_ICInvBal> stockBillItemList = new List<Kf_ICInvBal>(); + + foreach (DataRow row in dt.Rows) + { + Kf_ICInvBal item = new Kf_ICInvBal(); + + item.HYear = lastYear; + item.HPeriod = lastPeriod; + item.HWhID = Convert.ToInt32(row["浠撳簱"]); + item.HSPID = Convert.ToInt32(row["浠撲綅"]); + item.HMaterID = Convert.ToInt32(row["鐗╂枡"]); + item.HBeginQty = Convert.ToDecimal(row["鎬昏"]); + + oCN.RunProc("INSERT INTO Kf_ICInvBal (HYear, HPeriod, HWhID, HSPID, HMaterID, HBeginQty) VALUES('"+ item.HYear + "', '" + item.HPeriod + "', '" + item.HWhID + "', '" + item.HSPID + "', '" + item.HMaterID + "', '" + item.HBeginQty + "')"); + } + + // 鐜板湪stockBillItemList鍖呭惈浜嗕粠DataTable涓鍙栧苟澶勭悊杩囩殑鏁版嵁 + } + + else + { + //鏌ヨ涓婃湀姣忎釜浠撳簱,浠撲綅,鐗╂枡鎵�鏁伴噺澶氬皯,鏍规嵁涓婃湀鏁伴噺+鏈湀杩涘叆鏀嚭鏁伴噺,鎻掑叆鏈熷垵搴撳瓨琛� + string sql = "SELECT b.HWHID AS 浠撳簱, b.HSPID AS 浠撲綅,b.HMaterID AS 鐗╂枡," + + "SUM(CASE WHEN a.HYear = '" + fistYear + "' AND a.HPeriod = '" + fistPeriod + "' THEN b.HQty ELSE 0 END) AS 鏈熷垵," + + "SUM(CASE WHEN a.HYear = '" + lastYear + "' AND a.HPeriod = '" + lastPeriod + "' THEN b.HQty ELSE 0 END) AS 鏈湡, " + + "SUM(CASE WHEN (a.HYear = '" + fistYear + "' AND a.HPeriod = '" + fistPeriod + "') OR (a.HYear = '" + lastYear + "' AND a.HPeriod = '" + lastPeriod + "') THEN b.HQty ELSE 0 END) AS 鎬昏 " + + "FROM Kf_ICStockBillMain a INNER JOIN Kf_ICStockBillSub b ON a.HInterID = b.HInterID WHERE (a.HYear = '" + fistYear + "' AND a.HPeriod = '" + fistPeriod + "') OR (a.HYear = '" + lastYear + "' AND a.HPeriod = '" + lastPeriod + "') " + + "GROUP BY b.HWHID,b.HSPID,b.HMaterID ORDER BY b.HWHID,b.HSPID,b.HMaterID"; + ds = oCN.RunProcReturn(sql, "Kf_ICStockBillMain"); + DataTable dt = ds.Tables[0]; + List<Kf_ICInvBal> stockBillItemList = new List<Kf_ICInvBal>(); + + foreach (DataRow row in dt.Rows) + { + Kf_ICInvBal item = new Kf_ICInvBal(); + + item.HYear = fistYear; + item.HPeriod = fistPeriod; + item.HWhID = Convert.ToInt32(row["浠撳簱"]); + item.HSPID = Convert.ToInt32(row["浠撲綅"]); + item.HMaterID = Convert.ToInt32(row["鐗╂枡"]); + item.HBeginQty = Convert.ToDecimal(row["鎬昏"]); + + oCN.RunProc("INSERT INTO Kf_ICInvBal (HYear, HPeriod, HWhID, HSPID, HMaterID, HBeginQty) VALUES('" + item.HYear + "', '" + item.HPeriod + "', '" + item.HWhID + "', '" + item.HSPID + "', '" + item.HMaterID + "', '" + item.HBeginQty + "')"); + } + } + + + //鏌ヨ瑕佺粨璐︾殑鏃ユ湡 + ds = oCN.RunProcReturn("select top 1 * from h_v_Xt_AccountPeriodList where 鏄惁缁撹处 = '鏄�' Order by 寮�濮嬫棩鏈� DESC", "h_v_Xt_AccountPeriodList"); + //娣诲姞鍒楀悕 + foreach (DataColumn col in ds.Tables[0].Columns) + { + Type dataType = col.DataType; + string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; + columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//鑾峰彇鍒癉ataColumn鍒楀璞$殑鍒楀悕 + } + objJsonResult.code = "1"; + objJsonResult.count = 1; + objJsonResult.Message = "Sucess锛�"; + objJsonResult.data = ds.Tables[0]; + objJsonResult.list = columnNameList; + 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 = "Exception锛�" + e.ToString(); + objJsonResult.data = null; + return objJsonResult; + } + } + + + public class Kf_ICInvBal + { + public string HYear; //浼氳骞� + public string HPeriod; //浼氳鏈� + public int HWhID; //浠撳簱鍐呯爜 + public int HSPID; //浠撲綅鍐呯爜 + public int HMaterID; //鐗╂枡鍐呯爜 + public decimal HBeginQty; //鏈熷垵鏁伴噺 + } + + } } \ No newline at end of file -- Gitblit v1.9.1