Commit 42ddb880 authored by solho's avatar solho

關帳INSERT新資料FIXED

parent 8c4ccf3c
...@@ -115,8 +115,8 @@ namespace WebAPI.Controllers ...@@ -115,8 +115,8 @@ namespace WebAPI.Controllers
{ {
SqlCommand cmd = new SqlCommand("", Conn); SqlCommand cmd = new SqlCommand("", Conn);
String strsql = "", Permission_furtherSql = obj_input["Permission_furtherSql"].ToString(); 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 strsql += String.Format(@"select a.id, Settle_Date ,isClosed ,Emp_DS ,a.update_time,b.id as DStargetid from [esn_todos_Settle] a
left join [evw_qResult_EmpDS] b on a.DSNum=b.Emp_DSNum 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_Dept] c on a.DeptNum=c.targetID
left join [evw_qResult_EmpItem] d on a.ItemNum=d.Emp_ItemNum left join [evw_qResult_EmpItem] d on a.ItemNum=d.Emp_ItemNum
where 1=1 "); where 1=1 ");
...@@ -236,53 +236,80 @@ namespace WebAPI.Controllers ...@@ -236,53 +236,80 @@ namespace WebAPI.Controllers
{ {
string input = param.Input.ToString(); string input = param.Input.ToString();
JObject obj_input = JObject.Parse(input.ToString()); JObject obj_input = JObject.Parse(input.ToString());
try if (obj_input["Settle_Date"] == null)
{ {
using (SqlConnection Conn = new SqlConnection(connString)) response.Msg = "需設定關帳月份";
response.Code = "0";
}
else
{
try
{ {
SqlCommand cmd = new SqlCommand("", Conn); using (SqlConnection Conn = new SqlConnection(connString))
String strsql = ""; {
String @idswherecase = ""; SqlCommand cmd = new SqlCommand("", Conn);
strsql += String.Format(@"update [esn_todos_Settle] SET isClosed = 1, update_time = getdate(), update_user_id =@gUserID_wade String strsql = "";
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 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 and Settle_Date between @Settle_Date and @Settle_Date where 1=1 @wherecaseu ) a
where a.etsid=id @idswherecase ; where a.etsid=id ;
select @@ROWCOUNT; select @@ROWCOUNT;
MERGE INTO esn_todos_Settle WITH(HOLDLOCK) as target 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 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_DateNext and @Settle_DateNext) L1 and Settle_Date between @Settle_Date and @Settle_Date) L1
where 1=1 @idswherecase ) as source(DSNum, DeptNum, ItemNum, Settle_Date) where 1=1 @wherecasei ) as source(DSNum, DeptNum, ItemNum, Settle_Date)
on(target.DSNum = source.DSNum and target.Settle_Date = source.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) 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()) VALUES(@Settle_DateNext,source.DSNum,'' ,'',0,@gUserID_wade,getdate(),@gUserID_wade,getdate())
OUTPUT $action; "); OUTPUT $action; ");
JObject objPermission_furtherSql = JObject.Parse(obj_input["Permission_furtherSql"].ToString()); if (obj_input["Permission_furtherSql"] != null)
DateTime Settle_Date = Convert.ToDateTime(obj_input["Settle_Date"].ToString()); {
cmd.Parameters.Add("@Settle_Date", Settle_Date); JObject objPermission_furtherSql = JObject.Parse(obj_input["Permission_furtherSql"].ToString());
cmd.Parameters.Add("@Settle_DateNext", Settle_Date.AddMonths(1)); if (objPermission_furtherSql["firmID"] != null && !string.IsNullOrWhiteSpace(objPermission_furtherSql["firmID"].ToString()))
cmd.Parameters.Add("@isClosed", (obj_input["isClosed"].ToString() == "1" ? true : false)); {
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());
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)
strsql = strsql.Replace("@idswherecase", @idswherecase); {
string t = String.Join(",", obj_input["ids"]);
strsql = strsql.Replace("@ids", t);
}
}
cmd.Parameters.AddWithValue("@gUserID_wade", obj_input["gUserID_wade"].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));
cmd.Parameters.AddWithValue("@gUserID_wade", obj_input["gUserID_wade"].ToString());
cmd.CommandText = strsql; cmd.CommandText = strsql;
DataTable dt = SqlToDt(cmd); DataTable dt = SqlToDt(cmd);
response.Msg = "關帳完成"; response.Msg = "開關帳設定完成";
response.Code = "1"; response.Code = "1";
}
}
catch (Exception e)
{
response.Code = "0";
response.Msg = "Exception:" + e.StackTrace;
} }
}
catch (Exception e)
{
response.Code = "0";
response.Msg = "Exception:" + e.StackTrace;
} }
} }
else else
...@@ -398,6 +425,7 @@ namespace WebAPI.Controllers ...@@ -398,6 +425,7 @@ namespace WebAPI.Controllers
return result; return result;
} }
[Route("getCloseSettleConfigDS")] [Route("getCloseSettleConfigDS")]
[CorsHandle] [CorsHandle]
[HttpPost] [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