Example #1
0
        /// <summary>
        /// 削除
        /// </summary>
        /// <param name="p車輌ID"></param>
        /// <param name="p作成年月"></param>
        /// <returns></returns>
        public void DELETE_GetData(int p車輌ID, int p作成年月)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();
                using (var tran = new TransactionScope())
                {
                    var query = (from m05 in context.M05_CAR.Where(c => c.車輌ID == p車輌ID && c.削除日付 == null)
                                 from m05t in context.M05_TEN.Where(c => c.車輌KEY == m05.車輌KEY)
                                 select m05t);

                    if (query.Count() > 0)
                    {
                        foreach (var rec in query)
                        {
                            context.DeleteObject(rec);
                            context.SaveChanges();
                            tran.Complete();
                        }
                    }
                }

                return;
            }
        }
Example #2
0
        /// <summary>
        /// M91_OTANの削除
        /// </summary>
        /// <param name="m91OTAN">M91_OTAN_Member</param>
        public void Delete(int p得意先ID, DateTime p適用開始年月日)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();


                //得意先keyを特定
                var ret2 = from x in context.M01_TOK
                           where (x.得意先ID == p得意先ID)
                           select x;
                var m01 = ret2.FirstOrDefault();

                if (m01 == null)
                {
                    p支払先KEY = 0;
                }
                else
                {
                    p支払先KEY = m01.得意先KEY;
                }

                //削除行を特定
                var ret = from x in context.M91_OTAN
                          where (x.支払先KEY == p支払先KEY && x.適用開始年月日 == p適用開始年月日)
                          orderby x.支払先KEY
                          select x;
                var m91 = ret.FirstOrDefault();
                if (m91 != null)
                {
                    context.DeleteObject(m91);
                }
                context.SaveChanges();
            }
        }
Example #3
0
        /// <summary>
        /// M50_RTBLの重量の指定削除
        /// </summary>
        /// <param name="m50RTBL">M50_RTBL_Member</param>
        public void Jyuryou_Delete(int iタリフID, int i重量)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                var query = from x in context.M50_RTBL.Distinct()
                            where (x.タリフコード == iタリフID && x.重量 == i重量)
                            orderby x.タリフコード
                            select x;

                int query_count = query.Count();
                int cnt         = 0;

                for (int i = 0; i < query_count; i++)
                {
                    var m50 = query.FirstOrDefault();
                    cnt = cnt + 1;
                    if (cnt == 1)
                    {
                        context.DeleteObject(m50);
                    }
                    cnt = 0;

                    context.SaveChanges();
                }
            }
        }
Example #4
0
        /// <summary>
        /// S14_CARSBの物理削除
        /// </summary>
        /// <param name="s14SBdrvs">S14_CARSB_Member</param>
        public void Delete_Hendo(int?p車輌ID, int?p集計年月)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                try
                {
                    //削除行を特定
                    var ret = from x in context.S14_CARSB
                              where (x.車輌KEY == (from drv in context.M05_CAR where drv.車輌ID == p車輌ID select drv.車輌KEY).FirstOrDefault() &&
                                     x.集計年月 == p集計年月)
                              orderby x.車輌KEY, x.集計年月
                    select x;
                    foreach (var row in ret)
                    {
                        context.DeleteObject(row);
                    }
                    context.SaveChanges();
                }
                catch (Exception e)
                {
                }
            }
        }
Example #5
0
        /// <summary>
        /// 売上関連明細データ削除
        /// </summary>
        /// <param name="p明細番号"></param>
        /// <returns></returns>
        public int DeleteAllData(int p明細番号)
        {
            int count = 0;

            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();
                using (var tran = new TransactionScope())
                {
                    var rect01 = from x in context.T01_TRN
                                 where x.明細番号 == p明細番号 && x.入力区分 == 2
                                 select x;
                    foreach (var rec in rect01)
                    {
                        context.DeleteObject(rec);
                    }

                    context.SaveChanges();

                    tran.Complete();
                }
            }

            return(count);
        }
Example #6
0
        /// <summary>
        /// M88_SEQの物理削除
        /// </summary>
        /// <param name="m88seq">M88_SEQ</param>
        public void Delete(M88_SEQ m88seq)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                var m88 = context.M88_SEQ
                          .Where(w => w.明細番号ID == m88seq.明細番号ID)
                          .FirstOrDefault();

                context.DeleteObject(m88);
                context.SaveChanges();
            }
        }
Example #7
0
        /// <summary>
        /// M83_UKEの物理削除
        /// </summary>
        /// <param name="m83uke">M83_UKE_Member</param>
        public void Delete(M83_UKE_Member m83uke)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                //削除行を特定
                var ret = from x in context.M83_UKE
                          where (x.運賃計算区分ID == m83uke.運賃計算区分ID)
                          orderby x.運賃計算区分ID
                          select x;
                var m83 = ret.FirstOrDefault();

                context.DeleteObject(m83);
                context.SaveChanges();
            }
        }
Example #8
0
        /// <summary>
        /// M17_CYSNの物理削除
        /// </summary>
        /// <param name="m17cysn">M17_CYSN_Member</param>
        public void Delete(M17_CYSN_Member m17cysn)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                //削除行を特定
                var ret = from x in context.M17_CYSN
                          where (x.車輌KEY == m17cysn.車両KEY && x.年月 == m17cysn.年月)
                          orderby x.車輌KEY, x.年月
                select x;
                var m17 = ret.FirstOrDefault();

                context.DeleteObject(m17);
                context.SaveChanges();
            }
        }
Example #9
0
        /// <summary>
        /// M78_SYKの物理削除
        /// </summary>
        /// <param name="m78syk">M78_SYK_Member</param>
        public void Delete(M78_SYK_Member M75skk)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                //削除行を特定
                var ret = from x in context.M78_SYK
                          where (x.出勤区分ID == M75skk.出勤区分ID)
                          orderby x.出勤区分ID
                          select x;
                var m78 = ret.FirstOrDefault();

                context.DeleteObject(m78);
                context.SaveChanges();
            }
        }
Example #10
0
        /// <summary>
        /// M84_RIKの物理削除
        /// </summary>
        /// <param name="m84rik">M84_RIK_Member</param>
        public void Delete(M84_RIK_Member m84rik)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                //削除行を特定
                var ret = from x in context.M84_RIK
                          where (x.運輸局ID == m84rik.運輸局ID)
                          orderby x.運輸局ID
                          select x;
                var m84 = ret.FirstOrDefault();

                context.DeleteObject(m84);
                context.SaveChanges();
            }
        }
Example #11
0
        /// <summary>
        /// M15_KOMの物理削除
        /// </summary>
        /// <param name="m15kom">M15_KOM_Member</param>
        public void Delete(M15_KOM_Member m15kom)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                //削除行を特定
                var ret = from x in context.M15_KOM
                          where (x.プログラムID == m15kom.プログラムID && x.項目ID == m15kom.項目ID)
                          orderby x.プログラムID, x.項目ID
                select x;
                var m15 = ret.FirstOrDefault();

                context.DeleteObject(m15);
                context.SaveChanges();
            }
        }
Example #12
0
        /// <summary>
        /// M82_SEIの物理削除
        /// </summary>
        /// <param name="m82sei">M82_SEI_Member</param>
        public void Delete(M82_SEI_Member m82sei)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                //削除行を特定
                var ret = from x in context.M82_SEI
                          where (x.請求書区分ID == m82sei.請求書区分ID)
                          orderby x.請求書区分ID
                          select x;
                var m82 = ret.FirstOrDefault();

                context.DeleteObject(m82);
                context.SaveChanges();
            }
        }
Example #13
0
        /// <summary>
        /// T03_KTRNの物理削除
        /// </summary>
        /// <param name="t03ktrn">T03_KTRN_Member</param>
        public void Delete(T03_KTRN_Member t03ktrn)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                //削除行を特定
                var ret = from x in context.T03_KTRN
                          where x.明細番号 == t03ktrn.明細番号 &&
                          x.明細行 == t03ktrn.明細行
                          orderby x.明細番号, x.明細行
                select x;
                var t03 = ret.FirstOrDefault();

                context.DeleteObject(t03);
                context.SaveChanges();
            }
        }
Example #14
0
        /// <summary>
        /// T06_KYUSの物理削除
        /// </summary>
        /// <param name="t06kyus">T06_KYUS_Member</param>
        public void Delete(T06_KYUS_Member t06kyus)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                //削除行を特定
                var ret = from x in context.T06_KYUS
                          where x.車輌ID == t06kyus.車輌ID &&
                          x.休車開始日付 == t06kyus.休車開始日付
                          orderby x.車輌ID, x.休車開始日付
                select x;
                var t06 = ret.FirstOrDefault();

                context.DeleteObject(t06);
                context.SaveChanges();
            }
        }
Example #15
0
        /// <summary>
        /// T05_TTRNの物理削除
        /// </summary>
        /// <param name="t05ttrn">T05_TTRN_Member</param>
        public void Delete(T05_TTRN_Member t05ttrn)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                //削除行を特定
                var ret = from x in context.T05_TTRN
                          where x.乗務員KEY == t05ttrn.乗務員ID &&
                          x.配車日付 == t05ttrn.配車日付
                          orderby x.乗務員KEY, x.配車日付
                select x;
                var t05 = ret.FirstOrDefault();

                context.DeleteObject(t05);
                context.SaveChanges();
            }
        }
Example #16
0
        /// <summary>
        /// S14_CARSBの物理削除
        /// </summary>
        /// <param name="s14SBdrvs">S14_CARSB_Member</param>
        public void Delete(int?p車輌ID, int?p集計年月)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                //削除行を特定
                var ret = from x in context.S14_CARSB
                          where (x.車輌KEY == (from drv in context.M05_CAR where drv.車輌ID == p車輌ID select drv.車輌KEY).FirstOrDefault() &&
                                 x.集計年月 == p集計年月)
                          orderby x.車輌KEY, x.集計年月
                select x;
                var s14SB = ret.FirstOrDefault();

                context.DeleteObject(s14SB);
                context.SaveChanges();
            }
        }
Example #17
0
        /// <summary>
        /// S11_TOKGの物理削除
        /// </summary>
        /// <param name="s11tokg">S11_TOKG_Member</param>
        public void Delete(int?p得意先ID, int?p集計年月, int?p回数)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

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

                context.DeleteObject(s11);
                context.SaveChanges();
            }
        }
Example #18
0
        /// <summary>
        /// M92_KZEIの物理削除
        /// </summary>
        /// <param name="M92zei">M92_KZEI_Member</param>
        public void Delete(DateTime p適用開始年月日)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                //削除行を特定
                var ret = from x in context.M92_KZEI
                          where (x.適用開始年月日 == p適用開始年月日)
                          orderby x.適用開始年月日
                          select x;
                var M92 = ret.FirstOrDefault();

                if (M92 != null)
                {
                    context.DeleteObject(M92);
                }
                context.SaveChanges();
            }
        }
Example #19
0
        /// <summary>
        /// M73_ZEIの物理削除
        /// </summary>
        /// <param name="m73zei">M73_ZEI_Member</param>
        public void Delete(DateTime p適用開始日付)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                // 削除行を取得
                var m73 =
                    context.M73_ZEI
                    .Where(w => w.適用開始日付 == p適用開始日付)
                    .FirstOrDefault();

                if (m73 != null)
                {
                    context.DeleteObject(m73);
                }

                context.SaveChanges();
            }
        }
Example #20
0
        /// <summary>
        /// S13_DRVSBの物理削除
        /// </summary>
        /// <param name="s13SBdrvs">S13_DRVSB_Member</param>
        public void Delete_Hendo(int?p乗務員ID, int?p集計年月)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                //削除行を特定
                var ret = from x in context.S13_DRVSB
                          where (x.乗務員KEY == (from drv in context.M04_DRV where drv.乗務員ID == p乗務員ID select drv.乗務員KEY).FirstOrDefault() &&
                                 x.集計年月 == p集計年月)
                          orderby x.乗務員KEY, x.集計年月
                select x;

                foreach (var row in ret)
                {
                    context.DeleteObject(row);
                }

                context.SaveChanges();
            }
        }
Example #21
0
        /// <summary>
        /// M78_SYKのリスト登録
        /// </summary>
        /// <param name="p出勤区分ID">出勤区分ID</param>
        /// <returns>M78_SYK_Member</returns>
        public void GetListSYK(List <M78_SYK_Member> m78syk)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                // トランザクションのインスタンス化(開始)
                using (var tran = new TransactionScope())
                {
                    context.Connection.Open();

                    #region M78_SYK(出勤区分)
                    var ret1 = (from x in context.M78_SYK
                                select x).ToList();
                    foreach (var rec in ret1)
                    {
                        context.DeleteObject(rec);
                    }
                    int no = 1;
                    foreach (M78_SYK_Member syk in m78syk.OrderBy(x => x.出勤区分ID))
                    {
                        var dat = new M78_SYK()
                        {
                            出勤区分ID = syk.出勤区分ID,
                            出勤区分名  = syk.出勤区分名,
                            登録日時   = syk.登録日時,
                            更新日時   = DateTime.Now,
                            削除日付   = null
                        };
                        context.M78_SYK.ApplyChanges(dat);
                    }
                    context.SaveChanges();

                    tran.Complete();
                }
                #endregion
            }
        }
Example #22
0
        /// <summary>
        /// F9(登録ボタン)での登録
        /// </summary>
        public void NINSERT_GetData(List <SERCHE_MST32010> dt, string s作成年月)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                using (var tran = new TransactionScope())
                {
                    try
                    {
                        DateTime d年月   = Convert.ToDateTime(s作成年月.Substring(0, 4) + "/" + s作成年月.Substring(5, 2) + "/01");
                        int      i開始年月 = Convert.ToInt32(s作成年月.Substring(0, 4) + s作成年月.Substring(5, 2));
                        int      i終了年月 = AppCommon.IntParse(d年月.AddMonths(11).Year.ToString() + d年月.AddMonths(11).ToString("MM"));

                        var del = (from m17 in context.M17_CYSN where m17.年月 >= i開始年月 && m17.年月 <= i終了年月 select m17);
                        foreach (var row in del)
                        {
                            context.DeleteObject(row);
                        }
                        ;

                        foreach (var row in dt)
                        {
                            M17_CYSN m17_row = new M17_CYSN();
                            m17_row.車輌KEY = row.車輌KEY;
                            m17_row.年月    = row.年月1;
                            m17_row.売上予算  = row.月1;
                            m17_row.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row);
                            context.SaveChanges();

                            M17_CYSN m17_row2 = new M17_CYSN();
                            m17_row2.車輌KEY = row.車輌KEY;
                            m17_row2.年月    = row.年月2;
                            m17_row2.売上予算  = row.月2;
                            m17_row2.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row2);
                            context.SaveChanges();

                            M17_CYSN m17_row3 = new M17_CYSN();
                            m17_row3.車輌KEY = row.車輌KEY;
                            m17_row3.年月    = row.年月3;
                            m17_row3.売上予算  = row.月3;
                            m17_row3.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row3);
                            context.SaveChanges();

                            M17_CYSN m17_row4 = new M17_CYSN();
                            m17_row4.車輌KEY = row.車輌KEY;
                            m17_row4.年月    = row.年月4;
                            m17_row4.売上予算  = row.月4;
                            m17_row4.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row4);
                            context.SaveChanges();

                            M17_CYSN m17_row5 = new M17_CYSN();
                            m17_row5.車輌KEY = row.車輌KEY;
                            m17_row5.年月    = row.年月5;
                            m17_row5.売上予算  = row.月5;
                            m17_row5.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row5);
                            context.SaveChanges();

                            M17_CYSN m17_row6 = new M17_CYSN();
                            m17_row6.車輌KEY = row.車輌KEY;
                            m17_row6.年月    = row.年月6;
                            m17_row6.売上予算  = row.月6;
                            m17_row6.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row6);
                            context.SaveChanges();

                            M17_CYSN m17_row7 = new M17_CYSN();
                            m17_row7.車輌KEY = row.車輌KEY;
                            m17_row7.年月    = row.年月7;
                            m17_row7.売上予算  = row.月7;
                            m17_row7.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row7);
                            context.SaveChanges();

                            M17_CYSN m17_row8 = new M17_CYSN();
                            m17_row8.車輌KEY = row.車輌KEY;
                            m17_row8.年月    = row.年月8;
                            m17_row8.売上予算  = row.月8;
                            m17_row8.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row8);
                            context.SaveChanges();

                            M17_CYSN m17_row9 = new M17_CYSN();
                            m17_row9.車輌KEY = row.車輌KEY;
                            m17_row9.年月    = row.年月9;
                            m17_row9.売上予算  = row.月9;
                            m17_row9.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row9);
                            context.SaveChanges();

                            M17_CYSN m17_row10 = new M17_CYSN();
                            m17_row10.車輌KEY = row.車輌KEY;
                            m17_row10.年月    = row.年月10;
                            m17_row10.売上予算  = row.月10;
                            m17_row10.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row10);
                            context.SaveChanges();

                            M17_CYSN m17_row11 = new M17_CYSN();
                            m17_row11.車輌KEY = row.車輌KEY;
                            m17_row11.年月    = row.年月11;
                            m17_row11.売上予算  = row.月11;
                            m17_row11.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row11);
                            context.SaveChanges();

                            M17_CYSN m17_row12 = new M17_CYSN();
                            m17_row12.車輌KEY = row.車輌KEY;
                            m17_row12.年月    = row.年月12;
                            m17_row12.売上予算  = row.月12;
                            m17_row12.粗利予算  = 0;
                            // newのエンティティに対してはAcceptChangesで新規追加となる
                            context.M17_CYSN.ApplyChanges(m17_row12);
                            context.SaveChanges();
                        }
                        ;

                        tran.Complete();
                        return;
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
        }
Example #23
0
        /// <summary>
        /// S14_CARSBの更新 変動項目更新
        /// </summary>
        /// <param name="s14SBdrvs">S14_CARSB_Member</param>
        public void Update_Hendo(S14_CAR_Member s14drv, List <S14_CARSB_Member> s14SBHen, List <S14_CARSB_Member> s14SBJin, List <S14_CARSB_Member> s14SBKotei)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                // トランザクションのインスタンス化(開始)
                using (var tran = new TransactionScope())
                {
                    context.Connection.Open();

                    var ret = (from x in context.S14_CARSB
                               where x.車輌KEY == s14drv.車輌KEY && x.集計年月 == s14drv.集計年月
                               select x).ToList();
                    foreach (var rec1 in ret)
                    {
                        context.DeleteObject(rec1);
                    }

                    foreach (S14_CARSB_Member ddt in s14SBHen)
                    {
                        var dat = new S14_CARSB()
                        {
                            車輌KEY  = ddt.車輌KEY,
                            集計年月   = ddt.集計年月,
                            経費項目ID = ddt.経費項目ID,
                            登録日時   = ddt.登録日時,
                            更新日時   = DateTime.Now,
                            経費項目名  = ddt.経費項目名,
                            固定変動区分 = ddt.固定変動区分,
                            金額     = ddt.金額,
                        };
                        context.S14_CARSB.ApplyChanges(dat);
                    }

                    foreach (S14_CARSB_Member ddt in s14SBJin)
                    {
                        var dat = new S14_CARSB()
                        {
                            車輌KEY  = ddt.車輌KEY,
                            集計年月   = ddt.集計年月,
                            経費項目ID = ddt.経費項目ID,
                            登録日時   = ddt.登録日時,
                            更新日時   = DateTime.Now,
                            経費項目名  = ddt.経費項目名,
                            固定変動区分 = ddt.固定変動区分,
                            金額     = ddt.金額,
                        };
                        context.S14_CARSB.ApplyChanges(dat);
                    }

                    foreach (S14_CARSB_Member ddt in s14SBKotei)
                    {
                        var dat = new S14_CARSB()
                        {
                            車輌KEY  = ddt.車輌KEY,
                            集計年月   = ddt.集計年月,
                            経費項目ID = ddt.経費項目ID,
                            登録日時   = ddt.登録日時,
                            更新日時   = DateTime.Now,
                            経費項目名  = ddt.経費項目名,
                            固定変動区分 = ddt.固定変動区分,
                            金額     = ddt.金額,
                        };
                        context.S14_CARSB.ApplyChanges(dat);
                    }

                    context.SaveChanges();
                    tran.Complete();
                }
            }
        }
Example #24
0
        /// <summary>
        /// SRY05010
        /// </summary>
        /// <param name="p商品ID">車輌コード</param>
        /// <returns>T01</returns>
        public List <SRY05010_Member> SYUKEI(string p車輌From, string p車輌To, int?[] i車輌List, int?p作成締日, DateTime d集計期間From, DateTime d集計期間To, int i集計年月, string s車輌List, int i営業日数, int i一般管理費, int i固定再計算, DateTime d集計年月)
        {
            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                List <SRY05010_Member> retList  = new List <SRY05010_Member>();
                List <SRY05010_Date>   retList2 = new List <SRY05010_Date>();
                context.Connection.Open();


                for (DateTime dDate = d集計期間From; dDate <= d集計期間To; dDate = dDate.AddDays(1))
                {
                    retList2.Add(new SRY05010_Date()
                    {
                        日付 = dDate
                    });
                }

                DataTable dtTest = new DataTable();
                dtTest.Columns.Add("日付", typeof(DateTime));


                var query2 = (from d in retList2
                              from m05 in context.M05_CAR.Where(m05 => m05.削除日付 == null)
                              join t02 in context.T02_UTRN.Where(t02 => t02.出勤区分ID <= 4) on m05.車輌KEY equals t02.車輌KEY into t02Group
                              select new SRY05010_KADOU
                {
                    車輌KEY = m05.車輌ID,
                    日付 = d.日付,
                    回数 = t02Group.Where(t02g => t02g.勤務開始日 <= d.日付 && t02g.勤務終了日 >= d.日付).Any() == true ? 1 : 0,
                }).ToList();


                //var query3 = (from m05 in context.M05_CAR
                //              join q in query2 on m05.車輌KEY equals q.車輌KEY into qGroup
                //              select new SRY05010_KADOU2
                //              {
                //                  車輌KEY = m05.車輌KEY,
                //                  回数 = qGroup.Where(qg => qg.車輌KEY == m05.車輌KEY).Sum(qg => qg.回数),
                //              }).AsQueryable();

                var query = (from m05 in context.M05_CAR.Where(p => p.削除日付 == null)
                             join t01 in context.T01_TRN.Where(t01 => (t01.請求日付 >= d集計期間From && t01.請求日付 <= d集計期間To) && (t01.入力区分 != 3 || (t01.入力区分 == 3 && t01.明細行 != 1))) on m05.車輌KEY equals t01.車輌KEY into t01Group
                             from t01g in t01Group.DefaultIfEmpty()
                             join t02 in context.V_T02_UTRN.Where(t02 => t02.労務日 >= d集計期間From && t02.労務日 <= d集計期間To) on m05.車輌KEY equals t02.車輌KEY into t02Group
                             from t02g in t02Group.DefaultIfEmpty()
                             join t03 in context.T03_KTRN.Where(t03 => t03.経費発生日 >= d集計期間From && t03.経費発生日 <= d集計期間To) on m05.車輌KEY equals t03.車輌ID into t03Group
                             from t03g in t03Group.DefaultIfEmpty()
                             join s13 in context.S14_CAR.Where(s13 => s13.集計年月 == i集計年月) on m05.車輌KEY equals s13.車輌KEY into s13Group
                             from s13g in s13Group.DefaultIfEmpty()
                             join m04 in context.M04_DRV.Where(m04 => m04.削除日付 == null) on m05.乗務員KEY equals m04.乗務員KEY into m04Group
                             //join q in query2 on m05.車輌KEY equals q.車輌KEY into qGroup
                             select new SRY05010_Member
                {
                    KEY = m05.車輌KEY,
                    コード = m05.車輌ID,
                    集計年月 = i集計年月,
                    登録年月日 = s13g.登録日時,
                    自社部門ID = m05.自社部門ID,
                    車種ID = m05.車種ID,
                    乗務員KEY = m04Group.Min(m04 => m04.乗務員KEY),
                    営業日数 = i営業日数,
                    稼働日数 = 0,
                    //稼働日数 = qGroup.Where(q => q.車輌KEY == m05.車輌KEY).Sum(q => q.回数),
                    走行KM = t02Group.Where(t02 => t02.車輌KEY == m05.車輌KEY).Sum(t02 => t02.走行KM),
                    実車KM = t02Group.Where(t02 => t02.車輌KEY == m05.車輌KEY).Sum(t02 => t02.実車KM),
                    輸送屯数 = t02Group.Where(t02 => t02.車輌KEY == m05.車輌KEY).Sum(t02 => t02.輸送屯数),
                    運送収入 = t01Group.Where(t01 => t01.車輌KEY == m05.車輌KEY).Sum(t01 => t01.売上金額 + t01.請求割増1 + t01.請求割増2 + t01.通行料),
                    燃料L = t03Group.Where(t03 => t03.車輌ID == m05.車輌KEY && t03.経費項目ID == 401).Sum(t03 => t03.数量),
                    一般管理費 = (t01Group.Where(t01 => t01.車輌KEY == m05.車輌KEY).Sum(t01 => (decimal)t01.売上金額 + (decimal)t01.請求割増1 + (decimal)t01.請求割増2 + (decimal)t01.通行料) * (decimal)i一般管理費) / 100,
                    拘束時間 = t02Group.Where(t02 => t02.車輌KEY == m05.車輌KEY).Sum(t02 => t02.拘束時間),
                    運転時間 = t02Group.Where(t02 => t02.車輌KEY == m05.車輌KEY).Sum(t02 => t02.運転時間),
                    高速時間 = t02Group.Where(t02 => t02.車輌KEY == m05.車輌KEY).Sum(t02 => t02.高速時間),
                    作業時間 = t02Group.Where(t02 => t02.車輌KEY == m05.車輌KEY).Sum(t02 => t02.作業時間),
                    待機時間 = t02Group.Where(t02 => t02.車輌KEY == m05.車輌KEY).Sum(t02 => t02.待機時間),
                    休憩時間 = t02Group.Where(t02 => t02.車輌KEY == m05.車輌KEY).Sum(t02 => t02.休憩時間),
                    残業時間 = t02Group.Where(t02 => t02.車輌KEY == m05.車輌KEY).Sum(t02 => t02.残業時間),
                    深夜時間 = t02Group.Where(t02 => t02.車輌KEY == m05.車輌KEY).Sum(t02 => t02.深夜時間),
                }).AsQueryable();

                if (!(string.IsNullOrEmpty(p車輌From + p車輌To) && i車輌List.Length == 0))
                {
                    //車輌が検索対象に入っていない時全データ取得
                    if (string.IsNullOrEmpty(p車輌From + p車輌To))
                    {
                        query = query.Where(c => c.コード >= int.MaxValue);
                    }

                    //車輌From処理 Min値
                    if (!string.IsNullOrEmpty(p車輌From))
                    {
                        int i車輌FROM = AppCommon.IntParse(p車輌From);
                        query = query.Where(c => c.コード >= i車輌FROM);
                    }

                    //車輌To処理 Max値
                    if (!string.IsNullOrEmpty(p車輌To))
                    {
                        int i車輌TO = AppCommon.IntParse(p車輌To);
                        query = query.Where(c => c.コード <= i車輌TO);
                    }


                    if (i車輌List.Length > 0)
                    {
                        var intCause = i車輌List;


                        query = query.Union(from m05 in context.M05_CAR.Where(p => p.削除日付 == null)
                                            join t01 in context.T01_TRN.Where(t01 => (t01.請求日付 >= d集計期間From && t01.請求日付 <= d集計期間To) && (t01.入力区分 != 3 || (t01.入力区分 == 3 && t01.明細行 != 1))) on m05.車輌KEY equals t01.車輌KEY into t01Group
                                            from t01g in t01Group.DefaultIfEmpty()
                                            join t02 in context.V_T02_UTRN.Where(t02 => t02.労務日 >= d集計期間From && t02.労務日 <= d集計期間To) on m05.車輌KEY equals t02.車輌KEY into t02Group
                                            from t02g in t02Group.DefaultIfEmpty()
                                            join t03 in context.T03_KTRN.Where(t03 => t03.経費発生日 >= d集計期間From && t03.経費発生日 <= d集計期間To) on m05.車輌KEY equals t03.車輌ID into t03Group
                                            from t03g in t03Group.DefaultIfEmpty()
                                            join s13 in context.S14_CAR.Where(s13 => s13.集計年月 == i集計年月) on m05.車輌KEY equals s13.車輌KEY into s13Group
                                            from s13g in s13Group.DefaultIfEmpty()
                                            join m04 in context.M04_DRV.Where(m04 => m04.削除日付 == null) on m05.乗務員KEY equals m04.乗務員KEY into m04Group
                                            //join q in query2 on m05.車輌KEY equals q.車輌KEY into qGroup
                                            where intCause.Contains(m05.車輌ID)
                                            select new SRY05010_Member
                        {
                            KEY    = m05.車輌KEY,
                            コード    = m05.車輌ID,
                            集計年月   = i集計年月,
                            登録年月日  = s13g.登録日時,
                            自社部門ID = m05.自社部門ID,
                            車種ID   = m05.車種ID,
                            乗務員KEY = m04Group.Min(m04 => m04.乗務員KEY),
                            営業日数   = i営業日数,
                            稼働日数   = 0,
                            //稼働日数 = qGroup.Where(q => q.車輌KEY == m05.車輌KEY).Sum(q => q.回数),
                            走行KM  = t02Group.Where(t02 => t02.車輌KEY == m05.車輌KEY).Sum(t02 => t02.走行KM),
                            実車KM  = t02Group.Where(t02 => t02.車輌KEY == m05.車輌KEY).Sum(t02 => t02.実車KM),
                            輸送屯数  = t02Group.Where(t02 => t02.車輌KEY == m05.車輌KEY).Sum(t02 => t02.輸送屯数),
                            運送収入  = t01Group.Where(t01 => t01.車輌KEY == m05.車輌KEY).Sum(t01 => t01.売上金額 + t01.請求割増1 + t01.請求割増2 + t01.通行料),
                            燃料L   = t03Group.Where(t03 => t03.車輌ID == m05.車輌KEY && t03.経費項目ID == 401).Sum(t03 => t03.数量),
                            一般管理費 = (t01Group.Where(t01 => t01.車輌KEY == m05.車輌KEY).Sum(t01 => (decimal)t01.売上金額 + (decimal)t01.請求割増1 + (decimal)t01.請求割増2 + (decimal)t01.通行料) * (decimal)i一般管理費) / 100,
                            拘束時間  = t02Group.Where(t02 => t02.車輌KEY == m05.車輌KEY).Sum(t02 => t02.拘束時間),
                            運転時間  = t02Group.Where(t02 => t02.車輌KEY == m05.車輌KEY).Sum(t02 => t02.運転時間),
                            高速時間  = t02Group.Where(t02 => t02.車輌KEY == m05.車輌KEY).Sum(t02 => t02.高速時間),
                            作業時間  = t02Group.Where(t02 => t02.車輌KEY == m05.車輌KEY).Sum(t02 => t02.作業時間),
                            待機時間  = t02Group.Where(t02 => t02.車輌KEY == m05.車輌KEY).Sum(t02 => t02.待機時間),
                            休憩時間  = t02Group.Where(t02 => t02.車輌KEY == m05.車輌KEY).Sum(t02 => t02.休憩時間),
                            残業時間  = t02Group.Where(t02 => t02.車輌KEY == m05.車輌KEY).Sum(t02 => t02.残業時間),
                            深夜時間  = t02Group.Where(t02 => t02.車輌KEY == m05.車輌KEY).Sum(t02 => t02.深夜時間),
                        });



                        //車輌From処理 Min値
                        if (!string.IsNullOrEmpty(p車輌From))
                        {
                            int i車輌FROM = AppCommon.IntParse(p車輌From);
                            query = query.Where(c => c.コード >= i車輌FROM);
                        }

                        //車輌To処理 Max値
                        if (!string.IsNullOrEmpty(p車輌To))
                        {
                            int i車輌TO = AppCommon.IntParse(p車輌To);
                            query = query.Where(c => c.コード <= i車輌TO);
                        }

                        //集計期間処理
                        //query = query.Where(c => c.集計 > d集計期間From && d集計期間To > c.集計);
                    }


                    else
                    {
                        query = query.Where(c => c.コード > int.MinValue && c.コード < int.MaxValue);

                        ////締日処理 
                        //if (p作成締日 != 0)
                        //{
                        //    query = query.Where(c => c.締日 == p作成締日);
                        //}

                        ////集計期間処理
                        //query = query.Where(c => c.集計 > d集計期間From && d集計期間To > c.集計);
                    }
                }
                query = query.Distinct();



                //List<SRY05010_Member> queryLIST = query.ToList();
                List <SRY05010_KADOU> queryLIST2 = query2.ToList();

                //queryLIST = query.ToList();
                var queryLIST = (from q in query.ToArray()
                                 select new SRY05010_Member
                {
                    KEY = q.KEY,
                    コード = q.コード,
                    集計年月 = q.集計年月,
                    登録年月日 = q.登録年月日,
                    自社部門ID = q.自社部門ID,
                    車種ID = q.車種ID,
                    乗務員KEY = q.乗務員KEY,
                    営業日数 = q.営業日数,
                    稼働日数 = q.稼働日数,
                    走行KM = q.走行KM,
                    実車KM = q.実車KM,
                    輸送屯数 = q.輸送屯数,
                    運送収入 = q.運送収入,
                    燃料L = q.燃料L,
                    一般管理費 = q.一般管理費,
                    拘束時間 = KyoeiSystem.Framework.Common.LinqSub.分TO時間(q.拘束時間),
                    運転時間 = KyoeiSystem.Framework.Common.LinqSub.分TO時間(q.運転時間),
                    高速時間 = KyoeiSystem.Framework.Common.LinqSub.分TO時間(q.高速時間),
                    作業時間 = KyoeiSystem.Framework.Common.LinqSub.分TO時間(q.作業時間),
                    待機時間 = KyoeiSystem.Framework.Common.LinqSub.分TO時間(q.待機時間),
                    休憩時間 = KyoeiSystem.Framework.Common.LinqSub.分TO時間(q.休憩時間),
                    残業時間 = KyoeiSystem.Framework.Common.LinqSub.分TO時間(q.残業時間),
                    深夜時間 = KyoeiSystem.Framework.Common.LinqSub.分TO時間(q.深夜時間),
                }).ToList();


                for (int i = 0; i < queryLIST.Count; i++)
                {
                    queryLIST2 = query2.ToList();
                    queryLIST2 = queryLIST2.Where(q => q.車輌KEY == queryLIST[i].コード).ToList();
                    for (int ii = 0; ii < queryLIST2.Count; ii++)
                    {
                        if (queryLIST[i].コード == queryLIST2[ii].車輌KEY)
                        {
                            if (queryLIST2[ii].回数 != 0)
                            {
                                queryLIST[i].稼働日数 += queryLIST2[ii].回数;
                            }
                        }
                    }
                }

                int[] lst;
                lst = (from q in query select q.KEY).ToArray();

                //削除行を特定
                var ret = from x in context.S14_CAR
                          where x.集計年月 == i集計年月 && lst.Contains(x.車輌KEY)
                          select x;

                foreach (var r in ret)
                {
                    context.DeleteObject(r);
                }
                context.SaveChanges();


                do
                {
                }while ((from x in context.S14_CAR
                         where x.集計年月 == i集計年月 && lst.Contains(x.車輌KEY)
                         select x).Count() != 0);


                //sqlbulukcopy準備
                //DataTable dt = new DataTable("S14_CAR");
                //dt.Columns.Add("車輌KEY", Type.GetType("System.Int32"));
                //dt.Columns.Add("集計年月", Type.GetType("System.Int32"));
                //dt.Columns.Add("登録日時", Type.GetType("System.DateTime"));
                //dt.Columns.Add("更新日時", Type.GetType("System.DateTime"));
                //dt.Columns.Add("自社部門ID", Type.GetType("System.Int32"));
                //dt.Columns.Add("車種ID", Type.GetType("System.Int32"));
                //dt.Columns.Add("乗務員KEY", Type.GetType("System.Int32"));
                //dt.Columns.Add("営業日数", Type.GetType("System.Int32"));
                //dt.Columns.Add("稼動日数", Type.GetType("System.Int32"));
                //dt.Columns.Add("走行KM", Type.GetType("System.Int32"));
                //dt.Columns.Add("実車KM", Type.GetType("System.Int32"));
                //dt.Columns.Add("輸送屯数", Type.GetType("System.Decimal"));
                //dt.Columns.Add("運送収入", Type.GetType("System.Decimal"));
                //dt.Columns.Add("燃料L", Type.GetType("System.Decimal"));
                //dt.Columns.Add("一般管理費", Type.GetType("System.Decimal"));
                //dt.Columns.Add("拘束時間", Type.GetType("System.Decimal"));
                //dt.Columns.Add("運転時間", Type.GetType("System.Decimal"));
                //dt.Columns.Add("高速時間", Type.GetType("System.Decimal"));
                //dt.Columns.Add("作業時間", Type.GetType("System.Decimal"));
                //dt.Columns.Add("待機時間", Type.GetType("System.Decimal"));
                //dt.Columns.Add("休憩時間", Type.GetType("System.Decimal"));
                //dt.Columns.Add("残業時間", Type.GetType("System.Decimal"));
                //dt.Columns.Add("深夜時間", Type.GetType("System.Decimal"));

                var       properities = typeof(S14_CAR).GetProperties().Where(c => !c.Name.Contains("ChangeTracker"));
                DataTable dt          = new DataTable(typeof(S14_CAR).Name);
                foreach (var p in properities)
                {
                    Type ColType = Nullable.GetUnderlyingType(p.PropertyType) == null ? p.PropertyType : Nullable.GetUnderlyingType(p.PropertyType);
                    dt.Columns.Add(p.Name, ColType);
                }

                foreach (var r in queryLIST)
                {
                    DataRow dr = dt.NewRow();
                    dr[0]  = r.KEY;
                    dr[1]  = r.集計年月;
                    dr[2]  = (object)r.登録年月日 ?? DBNull.Value;
                    dr[3]  = DateTime.Now;
                    dr[4]  = (object)r.自社部門ID ?? DBNull.Value;
                    dr[5]  = (object)r.車種ID ?? DBNull.Value;
                    dr[6]  = (object)r.乗務員KEY ?? DBNull.Value;
                    dr[7]  = i営業日数 == null ? 0 : i営業日数;
                    dr[8]  = (int)(queryLIST.Where(c => c.コード == r.コード).Select(c => c.稼働日数)).FirstOrDefault();
                    dr[9]  = r.走行KM == null ? 0 : AppCommon.IntParse(r.走行KM.ToString());
                    dr[10] = r.実車KM == null ? 0 : AppCommon.IntParse(r.実車KM.ToString());
                    dr[11] = r.輸送屯数 == null ? 0 : AppCommon.DecimalParse(r.輸送屯数.ToString());
                    dr[12] = r.運送収入 == null ? 0 : AppCommon.DecimalParse(r.運送収入.ToString());
                    dr[13] = r.燃料L == null ? 0 : AppCommon.DecimalParse(r.燃料L.ToString());
                    dr[14] = r.一般管理費 == null ? 0 : Math.Round(AppCommon.DecimalParse(r.一般管理費.ToString()), 0, MidpointRounding.AwayFromZero);
                    dr[15] = r.拘束時間 == null ? 0 : AppCommon.DecimalParse(r.拘束時間.ToString());
                    dr[16] = r.運転時間 == null ? 0 : AppCommon.DecimalParse(r.運転時間.ToString());
                    dr[17] = r.高速時間 == null ? 0 : AppCommon.DecimalParse(r.高速時間.ToString());
                    dr[18] = r.作業時間 == null ? 0 : AppCommon.DecimalParse(r.作業時間.ToString());
                    dr[19] = r.待機時間 == null ? 0 : AppCommon.DecimalParse(r.待機時間.ToString());
                    dr[20] = r.休憩時間 == null ? 0 : AppCommon.DecimalParse(r.休憩時間.ToString());
                    dr[21] = r.残業時間 == null ? 0 : AppCommon.DecimalParse(r.残業時間.ToString());
                    dr[22] = r.深夜時間 == null ? 0 : AppCommon.DecimalParse(r.深夜時間.ToString());
                    dt.Rows.Add(dr);
                }

                try                 //SQL_BULK_COPY書込み
                {
                    var connect = CommonData.TRAC3_SQL_GetConnectionString();
                    using (var bulkCopy = new SqlBulkCopy(connect))
                    {
                        bulkCopy.DestinationTableName = dt.TableName;       // テーブル名をSqlBulkCopyに教える
                        bulkCopy.WriteToServer(dt);                         // bulkCopy実行
                    }
                }
                catch (Exception e)
                {
                }


                ////データ書き込み
                //foreach (var r in queryLIST)
                //{
                //	S14_CAR s13 = new S14_CAR();
                //	s13.車輌KEY = r.KEY;
                //	s13.集計年月 = r.集計年月;
                //	s13.登録日時 = r.登録年月日;
                //	s13.更新日時 = DateTime.Now;
                //	s13.自社部門ID = r.自社部門ID;
                //	s13.車種ID = r.車種ID;
                //	s13.乗務員KEY = r.乗務員KEY;
                //	s13.営業日数 = i営業日数 == null ? 0 : i営業日数;
                //	s13.稼動日数 = (int)(queryLIST.Where(c => c.コード == r.コード).Select(c => c.稼働日数)).FirstOrDefault();
                //	s13.走行KM = r.走行KM == null ? 0 : AppCommon.IntParse(r.走行KM.ToString());
                //	s13.実車KM = r.実車KM == null ? 0 : AppCommon.IntParse(r.実車KM.ToString());
                //	s13.輸送屯数 = r.輸送屯数 == null ? 0 : AppCommon.DecimalParse(r.輸送屯数.ToString());
                //	s13.運送収入 = r.運送収入 == null ? 0 : AppCommon.DecimalParse(r.運送収入.ToString());
                //	s13.燃料L = r.燃料L == null ? 0 : AppCommon.DecimalParse(r.燃料L.ToString());
                //	s13.一般管理費 = r.一般管理費 == null ? 0 : Math.Round( AppCommon.DecimalParse(r.一般管理費.ToString()), 0, MidpointRounding.AwayFromZero);
                //	s13.拘束時間 = r.拘束時間 == null ? 0 : AppCommon.DecimalParse(r.拘束時間.ToString());
                //	s13.運転時間 = r.運転時間 == null ? 0 : AppCommon.DecimalParse(r.運転時間.ToString());
                //	s13.高速時間 = r.高速時間 == null ? 0 : AppCommon.DecimalParse(r.高速時間.ToString());
                //	s13.作業時間 = r.作業時間 == null ? 0 : AppCommon.DecimalParse(r.作業時間.ToString());
                //	s13.待機時間 = r.待機時間 == null ? 0 : AppCommon.DecimalParse(r.待機時間.ToString());
                //	s13.休憩時間 = r.休憩時間 == null ? 0 : AppCommon.DecimalParse(r.休憩時間.ToString());
                //	s13.残業時間 = r.残業時間 == null ? 0 : AppCommon.DecimalParse(r.残業時間.ToString());
                //	s13.深夜時間 = r.深夜時間 == null ? 0 : AppCommon.DecimalParse(r.深夜時間.ToString());
                //	context.S14_CAR.ApplyChanges(s13);

                //}
                //context.SaveChanges();



                //経費項目集計↓↓↓↓↓↓↓↓↓↓↓↓↓↓
                lst = (from q in query select q.KEY).ToArray();

                DateTime d前月年月 = d集計年月;
                d前月年月 = d前月年月.AddMonths(-1);
                int i前月年月 = d前月年月.Year * 100 + d前月年月.Month;
                //前月データ取得
                var query_zen = from s13sb in context.S14_CARSB
                                where s13sb.集計年月 == i前月年月
                                select s13sb;

                //削除行を特定
                var ret_tougetu_del = from x in context.S14_CARSB
                                      where x.集計年月 == i集計年月 && lst.Contains(x.車輌KEY)
                                      select x;
                var ret_tougetu = ret_tougetu_del.ToList();
                //当月データを削除
                foreach (var r in ret_tougetu_del)
                {
                    context.DeleteObject(r);
                }
                context.SaveChanges();


                do
                {
                }while ((from x in context.S14_CARSB
                         where x.集計年月 == i集計年月 && lst.Contains(x.車輌KEY)
                         select x).Count() != 0);



                //当月データ集計
                var ret_k = (from m05 in context.M05_CAR.Where(m05 => m05.削除日付 == null)
                             from m07 in context.M07_KEI
                             join t02 in context.T03_KTRN.Where(t02 => t02.経費発生日 >= d集計期間From && t02.経費発生日 <= d集計期間To) on new { a = m05.車輌KEY, b = m07.経費項目ID } equals new { a = (int)t02.車輌ID, b = (int)t02.経費項目ID } into t02Group
                             //join s13 in ret_tougetu.Where(s13 => s13.集計年月 == i集計年月) on m05.車輌KEY equals s13.車輌KEY into s13Group
                             where lst.Contains(m05.車輌KEY)
                             select new SRY05010_sbMember
                {
                    金額 = m07.固定変動区分 == 1 ? (t02Group.Sum(t02 => t02.金額) == null ? 0 : (decimal)t02Group.Sum(t02 => t02.金額)) : 0,
                    //金額 = m07.固定変動区分 == 1 ? (t02Group.Sum(t02 => t02.金額) == null ? 0 : (decimal)t02Group.Sum(t02 => t02.金額)) : (s13Group.Where(s13 => s13.車輌KEY == m05.車輌KEY && s13.経費項目ID == m07.経費項目ID).Sum(s13 => s13.金額) == null ? 0 : s13Group.Where(s13 => s13.車輌KEY == m05.車輌KEY && s13.経費項目ID == m07.経費項目ID).Sum(s13 => s13.金額)),
                    経費項目ID = m07.経費項目ID,
                    経費項目名 = m07.経費項目名,
                    固定変動区分 = m07.固定変動区分,
                    更新日時 = DateTime.Now,
                    集計年月 = i集計年月,
                    車輌KEY = m05.車輌KEY,
                    乗務員KEY = m05.乗務員KEY,
                    登録日時 = DateTime.Now,
                    //登録日時 = s13Group.Min(s13 => s13.更新日時),
                }).ToList();

                try
                {
                    foreach (var row in ret_k)
                    {
                        if (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Count() == 0)
                        {
                            row.登録日時 = DateTime.Now;
                        }
                        else
                        {
                            row.登録日時 = ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Select(c => c.登録日時).FirstOrDefault();
                        }

                        if (row.経費項目ID == 102)
                        {
                            if (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Count() == 0 || i固定再計算 == 1)
                            {
                                row.金額 = ((context.M05_CAR.Where(m05 => m05.車輌KEY == row.車輌KEY).Select(c => c.固定自動車税)).FirstOrDefault()) == null ? 0 : (decimal)((context.M05_CAR.Where(m05 => m05.車輌KEY == row.車輌KEY).Select(c => c.固定自動車税)).FirstOrDefault());
                                row.金額 = Math.Round((row.金額 / 12), 0, MidpointRounding.AwayFromZero);
                            }
                            else
                            {
                                row.金額 = (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Select(s13 => s13.金額)).FirstOrDefault();
                            }
                            continue;
                        }
                        if (row.経費項目ID == 103)
                        {
                            if (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Count() == 0 || i固定再計算 == 1)
                            {
                                row.金額 = ((context.M05_CAR.Where(m05 => m05.車輌KEY == row.車輌KEY).Select(c => c.固定重量税)).FirstOrDefault()) == null ? 0 : (decimal)((context.M05_CAR.Where(m05 => m05.車輌KEY == row.車輌KEY).Select(c => c.固定重量税)).FirstOrDefault());
                                row.金額 = Math.Round((row.金額 / 12), 0, MidpointRounding.AwayFromZero);
                            }
                            else
                            {
                                row.金額 = (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Select(s13 => s13.金額)).FirstOrDefault();
                            }
                            continue;
                        }
                        if (row.経費項目ID == 104)
                        {
                            if (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Count() == 0 || i固定再計算 == 1)
                            {
                                row.金額 = ((context.M05_CAR.Where(m05 => m05.車輌KEY == row.車輌KEY).Select(c => c.固定取得税)).FirstOrDefault()) == null ? 0 : (decimal)((context.M05_CAR.Where(m05 => m05.車輌KEY == row.車輌KEY).Select(c => c.固定取得税)).FirstOrDefault());
                                row.金額 = Math.Round((row.金額 / 12), 0, MidpointRounding.AwayFromZero);
                            }
                            else
                            {
                                row.金額 = (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Select(s13 => s13.金額)).FirstOrDefault();
                            }
                            continue;
                        }
                        if (row.経費項目ID == 201)
                        {
                            if (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Count() == 0 || i固定再計算 == 1)
                            {
                                row.金額 = ((context.M05_CAR.Where(m05 => m05.車輌KEY == row.車輌KEY).Select(c => c.固定自賠責保険)).FirstOrDefault()) == null ? 0 : (decimal)((context.M05_CAR.Where(m05 => m05.車輌KEY == row.車輌KEY).Select(c => c.固定自賠責保険)).FirstOrDefault());
                                row.金額 = Math.Round((row.金額 / 12), 0, MidpointRounding.AwayFromZero);
                            }
                            else
                            {
                                row.金額 = (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Select(s13 => s13.金額)).FirstOrDefault();
                            }
                            continue;
                        }
                        if (row.経費項目ID == 202)
                        {
                            if (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Count() == 0 || i固定再計算 == 1)
                            {
                                row.金額 = ((context.M05_CAR.Where(m05 => m05.車輌KEY == row.車輌KEY).Select(c => c.固定車輌保険)).FirstOrDefault()) == null ? 0 : (decimal)((context.M05_CAR.Where(m05 => m05.車輌KEY == row.車輌KEY).Select(c => c.固定車輌保険)).FirstOrDefault());
                                row.金額 = Math.Round((row.金額 / 12), 0, MidpointRounding.AwayFromZero);
                            }
                            else
                            {
                                row.金額 = (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Select(s13 => s13.金額)).FirstOrDefault();
                            }
                            continue;
                        }
                        if (row.経費項目ID == 203)
                        {
                            if (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Count() == 0 || i固定再計算 == 1)
                            {
                                row.金額 = ((context.M05_CAR.Where(m05 => m05.車輌KEY == row.車輌KEY).Select(c => c.固定対人保険)).FirstOrDefault()) == null ? 0 : (decimal)((context.M05_CAR.Where(m05 => m05.車輌KEY == row.車輌KEY).Select(c => c.固定対人保険)).FirstOrDefault());
                                row.金額 = Math.Round((row.金額 / 12), 0, MidpointRounding.AwayFromZero);
                            }
                            else
                            {
                                row.金額 = (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Select(s13 => s13.金額)).FirstOrDefault();
                            }
                            continue;
                        }
                        if (row.経費項目ID == 204)
                        {
                            if (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Count() == 0 || i固定再計算 == 1)
                            {
                                row.金額 = ((context.M05_CAR.Where(m05 => m05.車輌KEY == row.車輌KEY).Select(c => c.固定対物保険)).FirstOrDefault()) == null ? 0 : (decimal)((context.M05_CAR.Where(m05 => m05.車輌KEY == row.車輌KEY).Select(c => c.固定対物保険)).FirstOrDefault());
                                row.金額 = Math.Round((row.金額 / 12), 0, MidpointRounding.AwayFromZero);
                            }
                            else
                            {
                                row.金額 = (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Select(s13 => s13.金額)).FirstOrDefault();
                            }
                            continue;
                        }
                        if (row.経費項目ID == 205)
                        {
                            if (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Count() == 0 || i固定再計算 == 1)
                            {
                                row.金額 = ((context.M05_CAR.Where(m05 => m05.車輌KEY == row.車輌KEY).Select(c => c.固定貨物保険)).FirstOrDefault()) == null ? 0 : (decimal)((context.M05_CAR.Where(m05 => m05.車輌KEY == row.車輌KEY).Select(c => c.固定貨物保険)).FirstOrDefault());
                                row.金額 = Math.Round((row.金額 / 12), 0, MidpointRounding.AwayFromZero);
                            }
                            else
                            {
                                row.金額 = (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Select(s13 => s13.金額)).FirstOrDefault();
                            }
                            continue;
                        }

                        if (row.経費項目ID == 301)
                        {
                            if (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Count() == 0 || i固定再計算 == 1)
                            {
                                row.金額 = ((context.M04_DRV.Where(m04 => m04.乗務員KEY == row.乗務員KEY).Select(c => c.固定給与)).FirstOrDefault()) == null ? 0 : (decimal)((context.M04_DRV.Where(m04 => m04.乗務員KEY == row.乗務員KEY).Select(c => c.固定給与)).FirstOrDefault());
                            }
                            else
                            {
                                row.金額 = (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Select(s13 => s13.金額)).FirstOrDefault();
                            }
                            continue;
                        }
                        if (row.経費項目ID == 303)
                        {
                            if (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Count() == 0 || i固定再計算 == 1)
                            {
                                row.金額 = ((context.M04_DRV.Where(m04 => m04.乗務員KEY == row.乗務員KEY).Select(c => c.固定賞与積立金)).FirstOrDefault()) == null ? 0 : (decimal)((context.M04_DRV.Where(m04 => m04.乗務員KEY == row.乗務員KEY).Select(c => c.固定賞与積立金)).FirstOrDefault());
                            }
                            else
                            {
                                row.金額 = (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Select(s13 => s13.金額)).FirstOrDefault();
                            }
                            continue;
                        }
                        if (row.経費項目ID == 304)
                        {
                            if (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Count() == 0 || i固定再計算 == 1)
                            {
                                row.金額 = ((context.M04_DRV.Where(m04 => m04.乗務員KEY == row.乗務員KEY).Select(c => c.固定福利厚生費)).FirstOrDefault()) == null ? 0 : (decimal)((context.M04_DRV.Where(m04 => m04.乗務員KEY == row.乗務員KEY).Select(c => c.固定福利厚生費)).FirstOrDefault());
                            }
                            else
                            {
                                row.金額 = (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Select(s13 => s13.金額)).FirstOrDefault();
                            }
                            continue;
                        }
                        if (row.経費項目ID == 305)
                        {
                            if (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Count() == 0 || i固定再計算 == 1)
                            {
                                row.金額 = ((context.M04_DRV.Where(m04 => m04.乗務員KEY == row.乗務員KEY).Select(c => c.固定法定福利費)).FirstOrDefault()) == null ? 0 : (decimal)((context.M04_DRV.Where(m04 => m04.乗務員KEY == row.乗務員KEY).Select(c => c.固定法定福利費)).FirstOrDefault());
                            }
                            else
                            {
                                row.金額 = (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Select(s13 => s13.金額)).FirstOrDefault();
                            }
                            continue;
                        }
                        if (row.経費項目ID == 306)
                        {
                            if (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Count() == 0 || i固定再計算 == 1)
                            {
                                row.金額 = ((context.M04_DRV.Where(m04 => m04.乗務員KEY == row.乗務員KEY).Select(c => c.固定退職引当金)).FirstOrDefault()) == null ? 0 : (decimal)((context.M04_DRV.Where(m04 => m04.乗務員KEY == row.乗務員KEY).Select(c => c.固定退職引当金)).FirstOrDefault());
                            }
                            else
                            {
                                row.金額 = (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Select(s13 => s13.金額)).FirstOrDefault();
                            }
                            continue;
                        }
                        if (row.経費項目ID == 307)
                        {
                            if (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Count() == 0 || i固定再計算 == 1)
                            {
                                row.金額 = ((context.M04_DRV.Where(m04 => m04.乗務員KEY == row.乗務員KEY).Select(c => c.固定労働保険)).FirstOrDefault()) == null ? 0 : (decimal)((context.M04_DRV.Where(m04 => m04.乗務員KEY == row.乗務員KEY).Select(c => c.固定労働保険)).FirstOrDefault());
                            }
                            else
                            {
                                row.金額 = (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Select(s13 => s13.金額)).FirstOrDefault();
                            }
                            continue;
                        }

                        //
                        if (row.固定変動区分 == 0)
                        {
                            if (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Count() == 0 || i固定再計算 == 1)
                            {
                                row.金額 = query_zen == null ? 0 : query_zen.Where(c => c.車輌KEY == row.車輌KEY && c.経費項目ID == row.経費項目ID).Select(c => c.金額).FirstOrDefault();
                            }
                            else
                            {
                                row.金額 = ret_tougetu == null ? 0 : (ret_tougetu.Where(s13 => s13.集計年月 == i集計年月 && s13.車輌KEY == row.車輌KEY && s13.経費項目ID == row.経費項目ID).Select(s13 => s13.金額)).FirstOrDefault();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }


                //var car = (from m05 in context.M05_CAR.Where(m05 => m05.削除日付 == null)
                //		   where lst.Contains(m05.車輌KEY)
                //		   select new M05_CAR()
                //			);

                //foreach (var row in car)
                //{
                //	if (row.固定自動車税 != null && row.固定自動車税 != 0)
                //	{
                //		ret_k.Add(new SRY05010_sbMember
                //		{
                //			金額 = row.固定自動車税 ?? 0,
                //			経費項目ID = 102,
                //			経費項目名 = (context.M07_KEI.Where(c => c.経費項目ID == 102).Select(c => c.経費項目名)).FirstOrDefault(),
                //			固定変動区分 = 0,
                //			更新日時 = DateTime.Now,
                //			車輌KEY = row.車輌KEY,
                //			集計年月 = i集計年月,
                //			登録日時 = DateTime.Now,
                //		});
                //	}
                //	if (row.固定重量税 != null && row.固定重量税 != 0)
                //	{
                //		ret_k.Add(new SRY05010_sbMember
                //		{
                //			金額 = row.固定重量税 ?? 0,
                //			経費項目ID = 103,
                //			経費項目名 = (context.M07_KEI.Where(c => c.経費項目ID == 103).Select(c => c.経費項目名)).FirstOrDefault(),
                //			固定変動区分 = 0,
                //			更新日時 = DateTime.Now,
                //			車輌KEY = row.車輌KEY,
                //			集計年月 = i集計年月,
                //			登録日時 = DateTime.Now,
                //		});
                //	}
                //	if (row.固定取得税 != null && row.固定取得税 != 0)
                //	{
                //		ret_k.Add(new SRY05010_sbMember
                //		{
                //			金額 = row.固定取得税 ?? 0,
                //			経費項目ID = 104,
                //			経費項目名 = (context.M07_KEI.Where(c => c.経費項目ID == 104).Select(c => c.経費項目名)).FirstOrDefault(),
                //			固定変動区分 = 0,
                //			更新日時 = DateTime.Now,
                //			車輌KEY = row.車輌KEY,
                //			集計年月 = i集計年月,
                //			登録日時 = DateTime.Now,
                //		});
                //	}
                //	if (row.固定自賠責保険 != null && row.固定自賠責保険 != 0)
                //	{
                //		ret_k.Add(new SRY05010_sbMember
                //		{
                //			金額 = row.固定自賠責保険 ?? 0,
                //			経費項目ID = 201,
                //			経費項目名 = (context.M07_KEI.Where(c => c.経費項目ID == 201).Select(c => c.経費項目名)).FirstOrDefault(),
                //			固定変動区分 = 0,
                //			更新日時 = DateTime.Now,
                //			車輌KEY = row.車輌KEY,
                //			集計年月 = i集計年月,
                //			登録日時 = DateTime.Now,
                //		});
                //	}
                //	if (row.固定車輌保険 != null && row.固定車輌保険 != 0)
                //	{
                //		ret_k.Add(new SRY05010_sbMember
                //		{
                //			金額 = row.固定車輌保険 ?? 0,
                //			経費項目ID = 202,
                //			経費項目名 = (context.M07_KEI.Where(c => c.経費項目ID == 202).Select(c => c.経費項目名)).FirstOrDefault(),
                //			固定変動区分 = 0,
                //			更新日時 = DateTime.Now,
                //			車輌KEY = row.車輌KEY,
                //			集計年月 = i集計年月,
                //			登録日時 = DateTime.Now,
                //		});
                //	}
                //	if (row.固定対人保険 != null && row.固定対人保険 != 0)
                //	{
                //		ret_k.Add(new SRY05010_sbMember
                //		{
                //			金額 = row.固定対人保険 ?? 0,
                //			経費項目ID = 203,
                //			経費項目名 = (context.M07_KEI.Where(c => c.経費項目ID == 203).Select(c => c.経費項目名)).FirstOrDefault(),
                //			固定変動区分 = 0,
                //			更新日時 = DateTime.Now,
                //			車輌KEY = row.車輌KEY,
                //			集計年月 = i集計年月,
                //			登録日時 = DateTime.Now,
                //		});
                //	}
                //	if (row.固定対物保険 != null && row.固定対物保険 != 0)
                //	{
                //		ret_k.Add(new SRY05010_sbMember
                //		{
                //			金額 = row.固定対物保険 ?? 0,
                //			経費項目ID = 204,
                //			経費項目名 = (context.M07_KEI.Where(c => c.経費項目ID == 204).Select(c => c.経費項目名)).FirstOrDefault(),
                //			固定変動区分 = 0,
                //			更新日時 = DateTime.Now,
                //			車輌KEY = row.車輌KEY,
                //			集計年月 = i集計年月,
                //			登録日時 = DateTime.Now,
                //		});
                //	}
                //	if (row.固定貨物保険 != null && row.固定貨物保険 != 0)
                //	{
                //		ret_k.Add(new SRY05010_sbMember
                //		{
                //			金額 = row.固定貨物保険 ?? 0,
                //			経費項目ID = 205,
                //			経費項目名 = (context.M07_KEI.Where(c => c.経費項目ID == 205).Select(c => c.経費項目名)).FirstOrDefault(),
                //			固定変動区分 = 0,
                //			更新日時 = DateTime.Now,
                //			車輌KEY = row.車輌KEY,
                //			集計年月 = i集計年月,
                //			登録日時 = DateTime.Now,
                //		});
                //	}
                //}


                //if (i固定再計算 == 1)
                //{
                //	foreach (var r in ret_k)
                //	{
                //		if (r.固定変動区分 == 0)
                //		{
                //			foreach (var r2 in query_zen)
                //			{
                //				if (r.経費項目ID == r2.経費項目ID && (r.経費項目ID != 102 && r.経費項目ID != 103 && r.経費項目ID != 104 && r.経費項目ID != 201 && r.経費項目ID != 202 && r.経費項目ID != 203 && r.経費項目ID != 204 && r.経費項目ID != 205))
                //				{
                //					r.金額 = r2.金額;
                //				}
                //			}
                //		}
                //	}
                //}


                //sqlbulukcopy準備
                DataTable CARSB_dt = new DataTable("S14_CARSB");
                CARSB_dt.Columns.Add("車輌KEY", Type.GetType("System.Int32"));
                CARSB_dt.Columns.Add("集計年月", Type.GetType("System.Int32"));
                CARSB_dt.Columns.Add("経費項目ID", Type.GetType("System.Int32"));
                CARSB_dt.Columns.Add("登録日時", Type.GetType("System.DateTime"));
                CARSB_dt.Columns.Add("更新日時", Type.GetType("System.DateTime"));
                CARSB_dt.Columns.Add("経費項目名", Type.GetType("System.String"));
                CARSB_dt.Columns.Add("固定変動区分", Type.GetType("System.Int32"));
                CARSB_dt.Columns.Add("金額", Type.GetType("System.Decimal"));

                foreach (var r in ret_k)
                {
                    DataRow dr = CARSB_dt.NewRow();
                    dr[0] = r.車輌KEY;
                    dr[1] = r.集計年月;
                    dr[2] = r.経費項目ID == null ? 0 : AppCommon.DecimalParse(r.経費項目ID.ToString());
                    dr[3] = (object)r.登録日時 ?? DBNull.Value;
                    dr[4] = (object)r.更新日時 ?? DBNull.Value;
                    dr[5] = (object)r.経費項目名 ?? DBNull.Value;
                    dr[6] = r.固定変動区分 == null ? 0 : AppCommon.IntParse(r.固定変動区分.ToString());
                    dr[7] = r.金額 == null ? 0 : AppCommon.DecimalParse(r.金額.ToString());

                    CARSB_dt.Rows.Add(dr);
                }

                try                 //SQL_BULK_COPY書込み
                {
                    var connect = CommonData.TRAC3_SQL_GetConnectionString();
                    using (var bulkCopy = new SqlBulkCopy(connect))
                    {
                        bulkCopy.DestinationTableName = CARSB_dt.TableName;       // テーブル名をSqlBulkCopyに教える
                        bulkCopy.WriteToServer(CARSB_dt);                         // bulkCopy実行
                    }
                }
                catch (Exception e)
                {
                }



                ////データ書き込み
                //foreach (var r in ret_k)
                //{
                //	S14_CARSB s13sb = new S14_CARSB();
                //	s13sb.金額 = r.金額;
                //	s13sb.経費項目ID = r.経費項目ID;
                //	s13sb.経費項目名 = r.経費項目名;
                //	s13sb.固定変動区分 = r.固定変動区分;
                //	s13sb.更新日時 = r.更新日時;
                //	s13sb.集計年月 = r.集計年月;
                //	s13sb.車輌KEY = r.車輌KEY;
                //	s13sb.登録日時 = r.登録日時;
                //	context.S14_CARSB.ApplyChanges(s13sb);

                //}
                //context.SaveChanges();



                //結果をリスト化
                retList = queryLIST.ToList();
                return(retList);
            }
        }
Example #25
0
        public int PutAllData(int p明細番号, int p明細行, List <T01_TRN_DATA> t01list, int 担当者ID, int p確認名称区分)
        {
            int count = 0;

            using (TRAC3Entities context = new TRAC3Entities(CommonData.TRAC3_GetConnectionString()))
            {
                context.Connection.Open();

                using (var tran = new TransactionScope())
                {
                    if (p明細番号 >= 0)
                    {
                        var rect01 = from x in context.T01_TRN
                                     where x.明細番号 == p明細番号 && x.明細行 == p明細行
                                     select x;
                        foreach (var rec in rect01)
                        {
                            context.DeleteObject(rec);
                        }
                    }
                    else
                    {
                        // 新番号取得
                        var 明細番号M = (from n in context.M88_SEQ
                                     where n.明細番号ID == 1
                                     select n
                                     ).FirstOrDefault();
                        if (明細番号M == null)
                        {
                            return(-1);
                        }
                        p明細番号        = 明細番号M.現在明細番号 + 1;
                        明細番号M.現在明細番号 = p明細番号;
                        明細番号M.AcceptChanges();
                        p明細行 = 1;
                    }

                    // T01

                    var t01trn = t01list[0];

                    if (t01trn.明細行 != 0 && t01trn.得意先ID != null)
                    {
                        var t01 = new T01_TRN();

                        var tokkey = (from t in context.M01_TOK where t.得意先ID == t01trn.得意先ID select(int?) t.得意先KEY).FirstOrDefault();
                        var shrkey = (from t in context.M01_TOK where t.得意先ID == t01trn.支払先ID select(int?) t.得意先KEY).FirstOrDefault();
                        var drvkey = (from t in context.M04_DRV where t.乗務員ID == t01trn.乗務員ID select(int?) t.乗務員KEY).FirstOrDefault();
                        var carkey = (from t in context.M05_CAR where t.車輌ID == t01trn.車輌ID select(int?) t.車輌KEY).FirstOrDefault();

                        t01.明細番号       = p明細番号;
                        t01.明細行        = t01trn.明細行;
                        t01.更新日時       = DateTime.Now;
                        t01.登録日時       = t01trn.登録日時 == null ? DateTime.Now : t01trn.登録日時;
                        t01.明細区分       = 1;
                        t01.入力区分       = 2;
                        t01.請求日付       = (DateTime)t01trn.請求日付;
                        t01.支払日付       = t01trn.支払日付;
                        t01.配送日付       = (DateTime)(t01trn.配送日付 == null?t01trn.請求日付:(DateTime)t01trn.配送日付);
                        t01.配送時間       = t01trn.配送時間;
                        t01.得意先KEY     = tokkey;
                        t01.請求内訳ID     = t01trn.請求内訳ID;
                        t01.車輌KEY      = carkey;
                        t01.車種ID       = t01trn.車種ID;
                        t01.支払先KEY     = shrkey;
                        t01.乗務員KEY     = drvkey;
                        t01.自社部門ID     = t01trn.自社部門ID;
                        t01.車輌番号       = t01trn.車輌番号;
                        t01.支払先名2次     = t01trn.支払先名2次;
                        t01.実運送乗務員     = t01trn.実運送乗務員;
                        t01.乗務員連絡先     = t01trn.乗務員連絡先;
                        t01.請求運賃計算区分ID = t01trn.請求運賃計算区分ID == null ? -1 : (int)t01trn.請求運賃計算区分ID;
                        t01.支払運賃計算区分ID = t01trn.支払運賃計算区分ID == null ? -1 : (int)t01trn.支払運賃計算区分ID;
                        t01.数量         = (decimal)(t01trn.数量 == null ? 0 : t01trn.数量);
                        t01.単位         = t01trn.単位;
                        t01.重量         = (decimal)(t01trn.重量 == null ? 0 : t01trn.重量);
                        t01.走行KM       = (int)(t01trn.走行KM == null?0:t01trn.走行KM);
                        t01.実車KM       = (int)(t01trn.実車KM == null?0:t01trn.実車KM);
                        t01.待機時間       = (decimal)(t01trn.待機時間 == null ? 0 : t01trn.待機時間);
                        t01.売上単価       = (decimal)(t01trn.売上単価 == null?0:t01trn.売上単価);
                        t01.売上金額       = (int)(t01trn.売上金額 == null ? 0 : t01trn.売上金額);
                        t01.通行料        = (int)(t01trn.通行料 == null ? 0 : t01trn.通行料);
                        t01.請求割増1      = (int)(t01trn.請求割増1 == null ? 0 : t01trn.請求割増1);
                        t01.請求割増2      = (int)(t01trn.請求割増2 == null?0:t01trn.請求割増2);
                        t01.支払単価       = (decimal)(t01trn.支払単価 == null ? 0 : t01trn.支払単価);
                        t01.支払金額       = (int)(t01trn.支払金額 == null ? 0 : t01trn.支払金額);
                        t01.支払通行料      = (int)(t01trn.支払通行料 == null ? 0 : t01trn.支払通行料);
                        t01.社内区分       = (int)(t01trn.社内区分 == null ? 1 : t01trn.社内区分);
                        t01.請求税区分      = (int)(t01trn.請求税区分 == null ? 0 : t01trn.請求税区分);
                        t01.支払税区分      = (int)(t01trn.支払税区分 == null?0:t01trn.支払税区分);
                        t01.売上未定区分     = (int)(t01trn.売上未定区分 == null?0:t01trn.売上未定区分);
                        t01.支払未定区分     = (int)(t01trn.支払未定区分 == null ? 0 : t01trn.支払未定区分);
                        t01.商品ID       = t01trn.商品ID;
                        t01.商品名        = t01trn.商品名;
                        t01.発地ID       = t01trn.発地ID;
                        t01.発地名        = t01trn.発地名;
                        t01.着地ID       = t01trn.着地ID;
                        t01.着地名        = t01trn.着地名;
                        t01.請求摘要ID     = t01trn.請求摘要ID;
                        t01.請求摘要       = t01trn.請求摘要;
                        t01.請求消費税      = (int)(t01trn.請求消費税 == null ? 0 : t01trn.請求消費税);
                        t01.支払割増1      = (int)(t01trn.支払割増1 == null ? 0 : t01trn.支払割増1);
                        t01.支払割増2      = (int)(t01trn.支払割増2 == null ? 0 : t01trn.支払割増2);
                        t01.支払消費税      = (int)(t01trn.支払消費税 == null ? 0 : t01trn.支払消費税);
                        t01.水揚金額       = (int)(t01trn.水揚金額 == null ? 0 : t01trn.水揚金額);
                        t01.社内備考ID     = t01trn.社内備考ID;
                        t01.社内備考       = t01trn.社内備考;
                        t01.入力者ID      = 担当者ID;
                        t01.確認名称区分     = p確認名称区分;

                        context.T01_TRN.ApplyChanges(t01);
                    }

                    context.SaveChanges();

                    tran.Complete();
                }
            }

            return(p明細番号);
        }