Exemplo n.º 1
0
        ///--------------------------------------------------------------------
        /// <summary>
        ///     納品単価マスタを取得する </summary>
        /// <param name="SyohinCD">
        ///     商品コード</param>
        /// <param name="TokuisakiCD">
        ///     得意先コード</param>
        /// <param name="TenDate">
        ///     店着日付</param>
        /// <param name="data">
        ///     納品単価マスタデータセット</param>
        /// <returns>
        ///     納品単価マスタクラス</returns>
        ///--------------------------------------------------------------------
        private ClsCsvData.ClsCsvNouhinTanka GetNouhinTanka(string SyohinCD, string TokuisakiCD, int TenDate, System.Data.DataTable data)
        {
            ClsCsvData.ClsCsvNouhinTanka clsCsvNouhin = new ClsCsvData.ClsCsvNouhinTanka
            {
                SYOHIN_CD       = "",
                SPECIAL_VAL_KBN = "",
                YUKO_START_YMD  = "",
                YUKO_END_YMD    = "",
                TOKUISAKI_CD    = "",
                NOUHIN_TANKA    = 0,
                KOURI_TANKA     = 0,
                DELFLG          = 0
            };

            DataRow[] rows = null;

            // 特売・得意先コード指定
            rows = data.AsEnumerable().Where(a => a["SPECIAL_VAL_KBN"].ToString() == global.TANKA_TOKUBAI &&
                                             a["TOKUISAKI_CD"].ToString().PadLeft(7, '0') == TokuisakiCD &&
                                             a["SYOHIN_CD"].ToString().PadLeft(8, '0') == SyohinCD &&
                                             Utility.StrtoInt(a["YUKO_START_YMD"].ToString()) <= TenDate &&
                                             Utility.StrtoInt(a["YUKO_END_YMD"].ToString()) >= TenDate &&
                                             a["DELFLG"].ToString() == global.FLGOFF)
                   .OrderByDescending(a => Utility.StrtoInt(a["YUKO_START_YMD"].ToString()))
                   .ToArray();

            if (rows.Count() == global.flgOff)
            {
                // 特売・チェーンCD指定:2020/08/24
                rows = data.AsEnumerable().Where(a => a["SPECIAL_VAL_KBN"].ToString() == global.TANKA_TOKUBAI &&
                                                 a["CHAIN_CD"].ToString().PadLeft(4, '0') == TokuisakiCD.Substring(0, 4) &&
                                                 a["SYOHIN_CD"].ToString().PadLeft(8, '0') == SyohinCD &&
                                                 Utility.StrtoInt(a["YUKO_START_YMD"].ToString()) <= TenDate &&
                                                 Utility.StrtoInt(a["YUKO_END_YMD"].ToString()) >= TenDate &&
                                                 a["DELFLG"].ToString() == global.FLGOFF)
                       .OrderByDescending(a => Utility.StrtoInt(a["YUKO_START_YMD"].ToString()))
                       .ToArray();
            }

            // 該当する特売データがなかったとき
            if (rows.Count() == global.flgOff)
            {
                // 定価・得意先コード指定
                rows = data.AsEnumerable().Where(a => a["SPECIAL_VAL_KBN"].ToString() == global.TANKA_TEIBAN &&
                                                 a["TOKUISAKI_CD"].ToString().PadLeft(7, '0') == TokuisakiCD &&
                                                 a["SYOHIN_CD"].ToString().PadLeft(8, '0') == SyohinCD &&
                                                 a["DELFLG"].ToString() == global.FLGOFF).ToArray();

                if (rows.Count() == global.flgOff)
                {
                    // 定価・チェーンCD指定:2020/08/24
                    rows = data.AsEnumerable().Where(a => a["SPECIAL_VAL_KBN"].ToString() == global.TANKA_TEIBAN &&
                                                     a["CHAIN_CD"].ToString().PadLeft(4, '0') == TokuisakiCD.Substring(0, 4) &&
                                                     a["SYOHIN_CD"].ToString().PadLeft(8, '0') == SyohinCD &&
                                                     a["DELFLG"].ToString() == global.FLGOFF).ToArray();
                }
            }

            foreach (var t in rows)
            {
                System.Diagnostics.Debug.WriteLine(t["SYOHIN_CD"].ToString() + "," + t["SPECIAL_VAL_KBN"].ToString() + "," +
                                                   t["YUKO_START_YMD"].ToString() + "," + t["YUKO_END_YMD"].ToString() + "," + t["TOKUISAKI_CD"].ToString() + "," +
                                                   t["NOUHIN_TANKA"].ToString() + "," + t["KOURI_TANKA"].ToString());

                clsCsvNouhin.SYOHIN_CD       = t["SYOHIN_CD"].ToString();
                clsCsvNouhin.SPECIAL_VAL_KBN = t["SPECIAL_VAL_KBN"].ToString();
                clsCsvNouhin.YUKO_START_YMD  = t["YUKO_START_YMD"].ToString();
                clsCsvNouhin.YUKO_END_YMD    = t["YUKO_END_YMD"].ToString();
                clsCsvNouhin.TOKUISAKI_CD    = t["TOKUISAKI_CD"].ToString();
                clsCsvNouhin.NOUHIN_TANKA    = Utility.StrtoDouble(t["NOUHIN_TANKA"].ToString());
                clsCsvNouhin.KOURI_TANKA     = Utility.StrtoDouble(t["KOURI_TANKA"].ToString());
                break;
            }

            return(clsCsvNouhin);
        }
Exemplo n.º 2
0
        ///----------------------------------------------------------------
        /// <summary>
        ///     基幹システムCSVデータ作成 </summary>
        /// <returns>
        ///     作成件数</returns>
        ///----------------------------------------------------------------
        private int CsvDataOutput()
        {
            int orderCnt = tblOrder.Count();

            if (orderCnt == 0)
            {
                MessageBox.Show("発注データはありません", "対象データなし", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(0);
            }

            progressBar1.Visible = true;
            int rCnt = 0;
            int dCnt = 0;

            try
            {
                Cursor = Cursors.WaitCursor;

                foreach (var r in tblOrder.OrderBy(a => a.ID))
                {
                    // 店着日付クラス配列作成
                    Utility.SetTenDate(tenDates, r);

                    string cTokuisakiCD = r.TokuisakiCode.ToString("D7");
                    string cTokuisakiNM = "";

                    // 2020/04/09
                    cTokuisakiNM = Utility.GetTokuisakiFromDataTable(cTokuisakiCD, global.dtTokuisaki).TOKUISAKI_NM;

                    string cNouhinDT = string.Empty;
                    string cDT       = global.DTKBN;

                    // 商品発注明細クラス : 2020/04/12
                    ClsGoods[] goods = Utility.SetGoodsTabla(r, tenDates, tblOrderHistories);

                    // 商品明細
                    for (int i = 0; i < goods.Length; i++)
                    {
                        if (goods[i].Code == string.Empty)
                        {
                            continue;
                        }

                        // 終売取消はネグる
                        if (goods[i].Syubai == global.SYUBAI_TORIKESHI)
                        {
                            continue;
                        }

                        int hCnt = 0;

                        // コメント化 2020/04/12
                        //// 発注数があるか?
                        //for (int iX = 0; iX < 7; iX++)
                        //{
                        //    hCnt += Utility.StrtoInt(goods[i].Suu[iX]);
                        //}

                        //// 発注数がなければネグる
                        //if (hCnt == global.flgOff)
                        //{
                        //    continue;
                        //}

                        // 商品情報取得
                        ClsCsvData.ClsCsvSyohin_New syohin = Utility.GetSyohinsFromDataTable(global.dtSyohin, goods[i].Code.PadLeft(8, '0'));  // 2020/04/09

                        // 店着日別発注数
                        for (int iX = 0; iX < goods[i].Target.Length; iX++)
                        {
                            // 対象ステータスで判断:2020/04/13
                            if (!goods[i].Target[iX])
                            {
                                continue;
                            }

                            if (Utility.StrtoInt(goods[i].Suu[iX]) == global.flgOff)
                            {
                                // 発注数空白、0はネグる
                                continue;
                            }

                            // 納品日(店着日)
                            cNouhinDT = tenDates[iX].Year + tenDates[iX].Month.PadLeft(2, '0') + tenDates[iX].Day.PadLeft(2, '0');

                            // 納品単価取得
                            ClsCsvData.ClsCsvNouhinTanka clsTanka = GetNouhinTanka(goods[i].Code, cTokuisakiCD, Utility.StrtoInt(cNouhinDT), global.dtSyohinNoukaBaika);

                            // CSVクラス配列追加
                            Array.Resize(ref csvDatas, dCnt + 1);
                            csvDatas[dCnt] = new ClsCsvData.ClsCsvCSV()
                            {
                                TOKUISAKI_CD = cTokuisakiCD,
                                TOKUISAKI_NM = cTokuisakiNM,
                                NOUHIN_DATE  = cNouhinDT,
                                SYOHIN_CD    = goods[i].Code.PadLeft(8, '0'),
                                SYOHIN_NM    = syohin.SYOHIN_NM,
                                SUU          = goods[i].Suu[iX],

                                // 納品単価マスタから取得 2020/08/06
                                NOUKA = clsTanka.NOUHIN_TANKA.ToString(),   // 2020/08/06
                                BAIKA = clsTanka.KOURI_TANKA.ToString(),    // 2020/08/06

                                // コメント化 2020/08/06
                                //NOUKA = goods[i].Nouka.ToString(),
                                //BAIKA = goods[i].Baika.ToString(),

                                DT_KBN = global.DTKBN
                            };

                            // リストビューに表示
                            listBox1.Items.Add(cTokuisakiCD + " " + cTokuisakiNM + " " + cNouhinDT.Substring(0, 4) + "/" + cNouhinDT.Substring(4, 2) + "/" + cNouhinDT.Substring(6, 2) + " " +
                                               goods[i].Code.PadLeft(8, '0') + " " + syohin.SYOHIN_NM + "(" + goods[i].Suu[iX] + ")");

                            listBox1.TopIndex = listBox1.Items.Count - 1;

                            // プログレスバー
                            progressBar1.Value = (rCnt + 1) * 100 / orderCnt;
                            //System.Threading.Thread.Sleep(10);
                            Application.DoEvents();

                            dCnt++;
                        }
                    }

                    rCnt++;
                }

                listBox1.Items.Add("終了しました..... 出力件数 " + dCnt.ToString("#,##0") + "件");

                listBox1.TopIndex = listBox1.Items.Count - 1;
                System.Threading.Thread.Sleep(500);
                Application.DoEvents();

                Cursor = Cursors.Default;

                if (csvDatas != null)
                {
                    // ファイルへ書き出し
                    CsvDataWrite(csvDatas);

                    // 終了メッセージ
                    MessageBox.Show(csvDatas.Length + "件のCSVデータ出力が終了しました", "処理完了", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    return(csvDatas.Length);
                }
                else
                {
                    return(global.flgOff);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

                if (csvDatas != null)
                {
                    return(csvDatas.Length);
                }
                else
                {
                    return(global.flgOff);
                }
            }
        }