Exemplo n.º 1
0
        /// <summary>
        /// S11_TOKGの新規追加
        /// </summary>
        /// <param name="s11tokg">S11_TOKG_Member</param>
        public void Insert(S11_TOKG_Member s11tokg)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                S11_TOKG s11 = new S11_TOKG();
                s11.得意先KEY  = s11tokg.得意先KEY;
                s11.集計年月    = s11tokg.集計年月;
                s11.回数      = s11tokg.回数;
                s11.登録日時    = s11tokg.登録日時;
                s11.更新日時    = s11tokg.更新日時;
                s11.月集計開始日  = s11tokg.月集計開始日;
                s11.月集計終了日  = s11tokg.月集計終了日;
                s11.月次前月残高  = s11tokg.月次前月残高;
                s11.月次入金現金  = s11tokg.月次入金現金;
                s11.月次入金手形  = s11tokg.月次入金手形;
                s11.月次入金その他 = s11tokg.月次入金その他;
                s11.月次売上金額  = s11tokg.月次売上金額;
                s11.月次通行料   = s11tokg.月次通行料;
                s11.月次課税売上  = s11tokg.月次課税売上;
                s11.月次非課税売上 = s11tokg.月次非課税売上;
                s11.月次消費税   = s11tokg.月次消費税;
                s11.月次内傭車売上 = s11tokg.月次内傭車売上;
                s11.月次内傭車料  = s11tokg.月次内傭車料;
                s11.月次未定件数  = s11tokg.月次未定件数;
                s11.月次件数    = s11tokg.月次件数;
                s11.締日      = s11tokg.締日;

                try
                {
                    // newのエンティティに対してはAcceptChangesで新規追加となる
                    context.S11_TOKG.ApplyChanges(s11);
                    context.SaveChanges();
                }
                catch (UpdateException ex)
                {
                    // PKey違反等
                    Console.WriteLine(ex);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// S11_TOKGの更新
        /// </summary>
        /// <param name="s11tokg">S11_TOKG_Member</param>
        public void Update(S11_TOKG_Member s11tokg)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                // トランザクションのインスタンス化(開始)
                using (var tran = new TransactionScope())
                {
                    context.Connection.Open();

                    //更新行を特定
                    var ret = from x in context.S11_TOKG
                              where (x.得意先KEY == (from tok in context.M01_TOK where tok.得意先ID == s11tokg.得意先KEY select tok.得意先KEY).FirstOrDefault() &&
                                     x.集計年月 == s11tokg.集計年月 && x.回数 == s11tokg.回数)
                              select x;
                    var s11 = ret.FirstOrDefault();

                    if ((s11 != null))
                    {
                        s11.得意先KEY  = (from tok in context.M01_TOK where tok.得意先ID == s11tokg.得意先KEY select tok.得意先KEY).FirstOrDefault();
                        s11.集計年月    = s11tokg.集計年月;
                        s11.回数      = s11tokg.回数;
                        s11.登録日時    = s11tokg.登録日時;
                        s11.更新日時    = s11tokg.更新日時;
                        s11.月集計開始日  = s11tokg.月集計開始日;
                        s11.月集計終了日  = s11tokg.月集計終了日;
                        s11.月次前月残高  = s11tokg.月次前月残高;
                        s11.月次入金現金  = s11tokg.月次入金現金;
                        s11.月次入金手形  = s11tokg.月次入金手形;
                        s11.月次入金その他 = s11tokg.月次入金その他;
                        s11.月次売上金額  = s11tokg.月次売上金額;
                        s11.月次通行料   = s11tokg.月次通行料;
                        s11.月次課税売上  = s11tokg.月次課税売上;
                        s11.月次非課税売上 = s11tokg.月次非課税売上;
                        s11.月次消費税   = s11tokg.月次消費税;
                        s11.月次内傭車売上 = s11tokg.月次内傭車売上;
                        s11.月次内傭車料  = s11tokg.月次内傭車料;
                        s11.月次未定件数  = s11tokg.月次未定件数;
                        s11.月次件数    = s11tokg.月次件数;
                        s11.締日      = s11tokg.締日;

                        s11.AcceptChanges();
                    }
                    else
                    {
                        context.S11_TOKG.AddObject(
                            new S11_TOKG()
                        {
                            得意先KEY  = (from tok in context.M01_TOK where tok.得意先ID == s11tokg.得意先KEY select tok.得意先KEY).FirstOrDefault(),
                            集計年月    = s11tokg.集計年月,
                            回数      = s11tokg.回数,
                            登録日時    = s11tokg.登録日時,
                            更新日時    = s11tokg.更新日時,
                            月集計開始日  = s11tokg.月集計開始日,
                            月集計終了日  = s11tokg.月集計終了日,
                            月次前月残高  = s11tokg.月次前月残高,
                            月次入金現金  = s11tokg.月次入金現金,
                            月次入金手形  = s11tokg.月次入金手形,
                            月次入金その他 = s11tokg.月次入金その他,
                            月次売上金額  = s11tokg.月次売上金額,
                            月次通行料   = s11tokg.月次通行料,
                            月次課税売上  = s11tokg.月次課税売上,
                            月次非課税売上 = s11tokg.月次非課税売上,
                            月次消費税   = s11tokg.月次消費税,
                            月次内傭車売上 = s11tokg.月次内傭車売上,
                            月次内傭車料  = s11tokg.月次内傭車料,
                            月次未定件数  = s11tokg.月次未定件数,
                            月次件数    = s11tokg.月次件数,
                            締日      = s11tokg.締日,
                        }
                            );

                        context.SaveChanges();
                        //var p2 = (from x in context.S11_TOKG where x.得意先KEY == s11tokg.得意先KEY && x.集計年月 == s11tokg.集計年月 && x.回数 == s11tokg.回数 select x.得意先KEY).FirstOrDefault();
                        //s11tokg.得意先KEY = p2;
                    }

                    context.SaveChanges();

                    tran.Complete();
                }
            }
        }