private void Save_Departments(dynamic data, DBCRMTree db) { var s_departments = JsonConvert.SerializeObject(data.departments.changes); List <CT_Dept_Name> departments = JsonConvert.DeserializeObject <List <CT_Dept_Name> >(s_departments); foreach (var pdn in departments) { pdn.PDN_AD_Code = UserSession.DealerEmpl.DE_AD_OM_Code; pdn.PDN_Update_dt = DateTime.Now; if (pdn.PDN_Code > 0) { pdn.Update(new string[] { "PDN_Name_EN", "PDN_Name_CN", "PDN_Update_dt" }); } else { pdn.PDN_Code = (short)pdn.Insert(); } if (null != pdn.EX_Values) { foreach (var v in pdn.EX_Values) { v.DV_PDN_Code = pdn.PDN_Code; v.DV_Update_dt = DateTime.Now; if (CT_Dept_Value.Exists("DV_PDN_Code = @DV_PDN_Code AND DV_PDV_Code = @DV_PDV_Code", v)) { db.Update <CT_Dept_Value>(@" SET DV_Value = @DV_Value, DV_Update_dt = @DV_Update_dt WHERE DV_PDN_Code = @DV_PDN_Code AND DV_PDV_Code = @DV_PDV_Code", v); } else { v.Insert(); } } } } var s_deletes = JsonConvert.SerializeObject(data.departments.deletes); List <CT_Dept_Name> deletes = JsonConvert.DeserializeObject <List <CT_Dept_Name> >(s_deletes); foreach (var d in deletes) { db.Execute("DELETE FROM CT_Dept_Values WHERE DV_PDN_Code = @0", d.PDN_Code); d.Delete(); } }
private void Save_Schedule(dynamic data, DBCRMTree db) { var s_schedule = JsonConvert.SerializeObject(data.schedule); if (string.IsNullOrWhiteSpace(s_schedule)) { return; } CT_Daily_PLanner daily = JsonConvert.DeserializeObject <CT_Daily_PLanner>(s_schedule); daily.DP_AU_AD_Code = UserSession.DealerEmpl.DE_AD_OM_Code; daily.DP_Update_dt = DateTime.Now; if (CT_Daily_PLanner.Exists("DP_UType = @0 AND DP_AU_AD_Code = @1", daily.DP_UType, daily.DP_AU_AD_Code)) { db.Update <CT_Daily_PLanner>(@" SET [DP_D1_AM_S] = @DP_D1_AM_S ,[DP_D1_AM_E] = @DP_D1_AM_E ,[DP_D1_PM_S] = @DP_D1_PM_S ,[DP_D1_PM_E] = @DP_D1_PM_E ,[DP_D2_AM_S] = @DP_D2_AM_S ,[DP_D2_AM_E] = @DP_D2_AM_E ,[DP_D2_PM_S] = @DP_D2_PM_S ,[DP_D2_PM_E] = @DP_D2_PM_E ,[DP_D3_AM_S] = @DP_D3_AM_S ,[DP_D3_AM_E] = @DP_D3_AM_E ,[DP_D3_PM_S] = @DP_D3_PM_S ,[DP_D3_PM_E] = @DP_D3_PM_E ,[DP_D4_AM_S] = @DP_D4_AM_S ,[DP_D4_AM_E] = @DP_D4_AM_E ,[DP_D4_PM_S] = @DP_D4_PM_S ,[DP_D4_PM_E] = @DP_D4_PM_E ,[DP_D5_AM_S] = @DP_D5_AM_S ,[DP_D5_AM_E] = @DP_D5_AM_E ,[DP_D5_PM_S] = @DP_D5_PM_S ,[DP_D5_PM_E] = @DP_D5_PM_E ,[DP_D6_AM_S] = @DP_D6_AM_S ,[DP_D6_AM_E] = @DP_D6_AM_E ,[DP_D6_PM_S] = @DP_D6_PM_S ,[DP_D6_PM_E] = @DP_D6_PM_E ,[DP_D7_AM_S] = @DP_D7_AM_S ,[DP_D7_AM_E] = @DP_D7_AM_E ,[DP_D7_PM_S] = @DP_D7_PM_S ,[DP_D7_PM_E] = @DP_D7_PM_E ,[DP_Update_dt] = @DP_Update_dt WHERE [DP_UType] = @DP_UType AND [DP_AU_AD_Code] = @DP_AU_AD_Code" , daily); } else { daily.Insert(); } }
private void Save_Resources(dynamic data, DBCRMTree db) { var s_resources = JsonConvert.SerializeObject(data.resources); if (string.IsNullOrWhiteSpace(s_resources)) { return; } List <CT_Daily_Resource> resources = JsonConvert.DeserializeObject <List <CT_Daily_Resource> >(s_resources); foreach (var resource in resources) { resource.DR_AU_AD_Code = UserSession.DealerEmpl.DE_AD_OM_Code; resource.DR_Update_dt = DateTime.Now; if (CT_Daily_Resource.Exists("DR_UType = @0 AND DR_AU_AD_Code = @1", resource.DR_UType, resource.DR_AU_AD_Code)) { db.Update <CT_Daily_Resource>(@" SET [DR_D1_AM] = @DR_D1_AM, [DR_D1_PM] = @DR_D1_PM, [DR_D2_AM] = @DR_D2_AM, [DR_D2_PM] = @DR_D2_PM, [DR_D3_AM] = @DR_D3_AM, [DR_D3_PM] = @DR_D3_PM, [DR_D4_AM] = @DR_D4_AM, [DR_D4_PM] = @DR_D4_PM, [DR_D5_AM] = @DR_D5_AM, [DR_D5_PM] = @DR_D5_PM, [DR_D6_AM] = @DR_D6_AM, [DR_D6_PM] = @DR_D6_PM, [DR_D7_AM] = @DR_D7_AM, [DR_D7_PM] = @DR_D7_PM, [DR_Update_dt] = @DR_Update_dt WHERE [DR_UType] = @DR_UType AND [DR_AU_AD_Code] = @DR_AU_AD_Code" , resource); } else { resource.Insert(); } } }