Commit 42ddb880 authored by solho's avatar solho

關帳INSERT新資料FIXED

parent 8c4ccf3c
......@@ -115,8 +115,8 @@ namespace WebAPI.Controllers
{
SqlCommand cmd = new SqlCommand("", Conn);
String strsql = "", Permission_furtherSql = obj_input["Permission_furtherSql"].ToString();
strsql += String.Format(@"select a.id, Settle_Date ,isClosed ,Emp_DS ,a.update_time from [esn_todos_Settle] a
left join [evw_qResult_EmpDS] b on a.DSNum=b.Emp_DSNum
strsql += String.Format(@"select a.id, Settle_Date ,isClosed ,Emp_DS ,a.update_time,b.id as DStargetid from [esn_todos_Settle] a
inner join [evw_qResult_EmpDS] b on a.DSNum=b.Emp_DSNum
left join [evw_qResult_Dept] c on a.DeptNum=c.targetID
left join [evw_qResult_EmpItem] d on a.ItemNum=d.Emp_ItemNum
where 1=1 ");
......@@ -236,46 +236,72 @@ namespace WebAPI.Controllers
{
string input = param.Input.ToString();
JObject obj_input = JObject.Parse(input.ToString());
if (obj_input["Settle_Date"] == null)
{
response.Msg = "需設定關帳月份";
response.Code = "0";
}
else
{
try
{
using (SqlConnection Conn = new SqlConnection(connString))
{
SqlCommand cmd = new SqlCommand("", Conn);
String strsql = "";
String @idswherecase = "";
strsql += String.Format(@"update [esn_todos_Settle] SET isClosed = 1, update_time = getdate(), update_user_id =@gUserID_wade
String wherecaseu = "", wherecasei = "";
strsql += String.Format(@"update [esn_todos_Settle] SET isClosed = @isClosed, update_time = getdate(), update_user_id =@gUserID_wade
from (select b.id as etsid,a.id as targetid, DSNum,DeptNum, ItemNum, Settle_Date from evw_qResult_EmpDS a inner join [esn_todos_Settle] b on a.Emp_DSNum=b.DSNum
and Settle_Date between @Settle_Date and @Settle_Date ) a
where a.etsid=id @idswherecase ;
and Settle_Date between @Settle_Date and @Settle_Date where 1=1 @wherecaseu ) a
where a.etsid=id ;
select @@ROWCOUNT;
MERGE INTO esn_todos_Settle WITH(HOLDLOCK) as target
USING( select Emp_DSNum,DeptNum, ItemNum, Settle_Date from (select a.id as targetid,Emp_DSNum,DeptNum, ItemNum, Settle_Date from evw_qResult_EmpDS a left join [esn_todos_Settle] b on a.Emp_DSNum=b.DSNum
and Settle_Date between @Settle_DateNext and @Settle_DateNext) L1
where 1=1 @idswherecase ) as source(DSNum, DeptNum, ItemNum, Settle_Date)
USING( select Emp_DSNum,DeptNum, ItemNum, @Settle_DateNext from (select a.id as targetid,Emp_DSNum,DeptNum, ItemNum, Settle_Date,b.id as etsid from evw_qResult_EmpDS a left join [esn_todos_Settle] b on a.Emp_DSNum=b.DSNum
and Settle_Date between @Settle_Date and @Settle_Date) L1
where 1=1 @wherecasei ) as source(DSNum, DeptNum, ItemNum, Settle_Date)
on(target.DSNum = source.DSNum and target.Settle_Date = source.Settle_Date)
-- WHEN MATCHED THEN UPDATE SET isClosed = 1, update_time = getdate(), update_user_id = @gUserID_wade
WHEN NOT MATCHED THEN INSERT(Settle_Date,DSNum,DeptNum,ItemNum,isClosed, update_user_id, update_time, Create_user_id, Create_time)
VALUES(@Settle_DateNext,source.DSNum,'' ,'',0,@gUserID_wade,getdate(),@gUserID_wade,getdate())
OUTPUT $action; ");
if (obj_input["Permission_furtherSql"] != null)
{
JObject objPermission_furtherSql = JObject.Parse(obj_input["Permission_furtherSql"].ToString());
if (objPermission_furtherSql["firmID"] != null && !string.IsNullOrWhiteSpace(objPermission_furtherSql["firmID"].ToString()))
{
wherecasei += " and targetid in(" + objPermission_furtherSql["firmID"].ToString() + ")";
wherecaseu += " and targetid in(" + objPermission_furtherSql["firmID"].ToString() + ")";
}
}
DateTime Settle_Date = Convert.ToDateTime(obj_input["Settle_Date"].ToString());
cmd.Parameters.Add("@Settle_Date", Settle_Date);
cmd.Parameters.Add("@Settle_DateNext", Settle_Date.AddMonths(1));
cmd.Parameters.Add("@isClosed", (obj_input["isClosed"].ToString() == "1" ? true : false));
if (obj_input["ids"] != null && !string.IsNullOrWhiteSpace(obj_input["ids"].ToString()))
{
wherecaseu += " and b.id in(@ids)";
wherecasei += " and etsid in(@ids)";
}
strsql = strsql.Replace("@wherecasei", wherecasei);
strsql = strsql.Replace("@wherecaseu", wherecaseu);
if (objPermission_furtherSql["firmID"] != null && !string.IsNullOrWhiteSpace(objPermission_furtherSql["firmID"].ToString()))
if (obj_input["ids"] != null && !string.IsNullOrWhiteSpace(obj_input["ids"].ToString()))
{
@idswherecase= " and targetid in(" + objPermission_furtherSql["firmID"].ToString() + ")";
JArray idsar = JArray.Parse(obj_input["ids"].ToString());
if (idsar.Count > 0)
{
string t = String.Join(",", obj_input["ids"]);
strsql = strsql.Replace("@ids", t);
}
}
strsql = strsql.Replace("@idswherecase", @idswherecase);
cmd.Parameters.Add("@Settle_Date", Settle_Date);
cmd.Parameters.Add("@Settle_DateNext", Settle_Date.AddMonths(1));
cmd.Parameters.Add("@isClosed", (obj_input["isClosed"].ToString() == "1" ? true : false));
cmd.Parameters.AddWithValue("@gUserID_wade", obj_input["gUserID_wade"].ToString());
cmd.CommandText = strsql;
DataTable dt = SqlToDt(cmd);
response.Msg = "關帳完成";
response.Msg = "開關帳設定完成";
response.Code = "1";
}
}
......@@ -285,6 +311,7 @@ namespace WebAPI.Controllers
response.Msg = "Exception:" + e.StackTrace;
}
}
}
else
{
response.Code = "0";
......@@ -398,6 +425,7 @@ namespace WebAPI.Controllers
return result;
}
[Route("getCloseSettleConfigDS")]
[CorsHandle]
[HttpPost]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment