/// <summary> /// S13_DRVSBの新規追加 /// </summary> /// <param name="s13SBdrvs">S13_DRVSB_Member</param> public void Insert(S13_DRVSB_Member s13SBdrvs) { using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString())) { context.Connection.Open(); S13_DRVSB s13SB = new S13_DRVSB(); s13SB.乗務員KEY = s13SBdrvs.乗務員KEY; s13SB.集計年月 = s13SBdrvs.集計年月; s13SB.経費項目ID = s13SBdrvs.経費項目ID; s13SB.登録日時 = s13SBdrvs.登録日時; s13SB.更新日時 = s13SBdrvs.更新日時; s13SB.経費項目名 = s13SBdrvs.経費項目名; s13SB.固定変動区分 = s13SBdrvs.固定変動区分; s13SB.金額 = s13SBdrvs.金額; try { // newのエンティティに対してはAcceptChangesで新規追加となる context.S13_DRVSB.ApplyChanges(s13SB); context.SaveChanges(); } catch (UpdateException ex) { // PKey違反等 Console.WriteLine(ex); } } }
/// <summary> /// S13_DRVSBの更新 変動項目更新 /// </summary> /// <param name="s13SBdrvs">S13_DRVSB_Member</param> public void Update_Hendo(S13_DRV_Member s13drv, List <S13_DRVSB_Member> s13SBHen, List <S13_DRVSB_Member> s13SBJin, List <S13_DRVSB_Member> s13SBKotei) { using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString())) { // トランザクションのインスタンス化(開始) using (var tran = new TransactionScope()) { context.Connection.Open(); var ret = (from x in context.S13_DRVSB where x.乗務員KEY == s13drv.乗務員KEY && x.集計年月 == s13drv.集計年月 select x).ToList(); foreach (var rec1 in ret) { context.DeleteObject(rec1); } foreach (S13_DRVSB_Member ddt in s13SBHen) { var dat = new S13_DRVSB() { 乗務員KEY = ddt.乗務員KEY, 集計年月 = ddt.集計年月, 経費項目ID = ddt.経費項目ID, 登録日時 = ddt.登録日時, 更新日時 = DateTime.Now, 経費項目名 = ddt.経費項目名, 固定変動区分 = ddt.固定変動区分, 金額 = ddt.金額, }; context.S13_DRVSB.ApplyChanges(dat); } foreach (S13_DRVSB_Member ddt in s13SBJin) { var dat = new S13_DRVSB() { 乗務員KEY = ddt.乗務員KEY, 集計年月 = ddt.集計年月, 経費項目ID = ddt.経費項目ID, 登録日時 = ddt.登録日時, 更新日時 = DateTime.Now, 経費項目名 = ddt.経費項目名, 固定変動区分 = ddt.固定変動区分, 金額 = ddt.金額, }; context.S13_DRVSB.ApplyChanges(dat); } foreach (S13_DRVSB_Member ddt in s13SBKotei) { var dat = new S13_DRVSB() { 乗務員KEY = ddt.乗務員KEY, 集計年月 = ddt.集計年月, 経費項目ID = ddt.経費項目ID, 登録日時 = ddt.登録日時, 更新日時 = DateTime.Now, 経費項目名 = ddt.経費項目名, 固定変動区分 = ddt.固定変動区分, 金額 = ddt.金額, }; context.S13_DRVSB.ApplyChanges(dat); } context.SaveChanges(); tran.Complete(); } } }