Example #1
0
        public DataTable M_VendorFTP_Select(M_VendorFTP_Entity mve)
        {
            string sp = "M_VendorFTP_Select";

            Dictionary <string, ValuePair> dic = new Dictionary <string, ValuePair>
            {
                { "@VendorCD", new ValuePair {
                      value1 = SqlDbType.VarChar, value2 = mve.VendorCD
                  } },
                { "@ChangeDate", new ValuePair {
                      value1 = SqlDbType.VarChar, value2 = mve.ChangeDate
                  } }
            };

            return(SelectData(dic, sp));
        }
Example #2
0
        /// <summary>
        /// CSV出力
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="dtNow"></param>
        /// <returns></returns>
        private bool ExportCsv(DataTable dt, DateTime dtNow)
        {
            try
            {
                //CSV出力データ取得
                if (dt.Rows.Count == 0)
                {
                    return(true);
                }

                var tables = dt.Rows.Cast <DataRow>()
                             .GroupBy(a => a.Field <string>("VendorCD"))
                             .Select(a => a.CopyToDataTable())
                             .ToArray();

                for (int i = 0; i < tables.Length; i++)
                {
                    //CSV出力処理
                    //VendorFTP_BL ble = new VendorFTP_BL();
                    string    strFullPath = string.Empty;
                    string    strPath     = string.Empty;
                    string    titleFlg    = "0";
                    DataTable dtFTP;

                    //出力先取得
                    M_VendorFTP_Entity mse = new M_VendorFTP_Entity
                    {
                        VendorCD   = tables[i].Rows[0]["VendorCD"].ToString(),
                        ChangeDate = dtNow.Date.ToString()
                    };

                    M_VendorFTP_DL vl = new M_VendorFTP_DL();
                    dtFTP = vl.M_VendorFTP_Select(mse);
                    if (dtFTP.Rows.Count == 0)
                    {
                        continue;
                    }

                    //サーバ名
                    strPath = dtFTP.Rows[0]["CreateServer"].ToString();
                    if (!strPath.EndsWith(@"\"))
                    {
                        strPath += @"\";
                    }

                    //フォルダ名
                    strPath += dtFTP.Rows[0]["CreateFolder"].ToString();
                    if (!Directory.Exists(strPath))
                    {
                        Directory.CreateDirectory(strPath);
                    }
                    if (!strPath.EndsWith(@"\"))
                    {
                        strPath += @"\";
                    }
                    strFullPath = strPath + Path.GetFileNameWithoutExtension(dtFTP.Rows[0]["FileName"].ToString()) + "_" + dtNow.ToString("yyyyMMddHHmmss") + ".csv";
                    titleFlg    = dtFTP.Rows[0]["TitleFLG"].ToString();

                    //CSV出力
                    //CSVファイルに書き込むときに使うEncoding
                    System.Text.Encoding enc = System.Text.Encoding.GetEncoding("Shift_JIS");

                    using (StreamWriter sw = new StreamWriter(strFullPath, false, enc))
                    {
                        int colCount     = tables[i].Columns.Count;
                        int lastColIndex = colCount - 2;

                        //ヘッダを書き込む
                        if (titleFlg == "1")
                        {
                            string field = "レコード区分,データ区分,発注者会社部署CD,発注者企業部署名" +
                                           ",受注者会社部署CD,受注者企業部署名,販売店会社部署CD,販売店会社部署名" +
                                           ",出荷先会社部署CD,出荷先会社部署名,発注NO,発注NO行,発注NO列,発注日" +
                                           ",納品日,発注区分,発注者商品分類,発注者商品CD,受注者品番" +
                                           ",メーカー規格1,メーカー規格2,単位,取引単価,標準上代,ブランド略名,商品略名,JANCD" +
                                           ",発注数,発注グループ番号,引当数,次回予定日,発注グループ行,エラーメッセージ";

                            sw.Write(field);
                            sw.Write("\r\n");
                        }

                        //レコードを書き込む
                        foreach (DataRow row in tables[i].Rows)
                        {
                            //最後の項目は書き込まない
                            for (int count = 0; count < colCount - 1; count++)
                            {
                                //書き込み
                                switch (count)
                                {
                                case 11:
                                case 12:
                                case 22:
                                case 23:
                                case 27:
                                case 29:
                                case 31:
                                    sw.Write(row[count]);
                                    break;

                                default:
                                    string field = EncloseDoubleQuotesIfNeed(row[count].ToString());
                                    sw.Write(field);
                                    break;
                                }

                                //カンマを書き込む
                                if (lastColIndex > count)
                                {
                                    sw.Write(',');
                                }
                            }
                            //改行する
                            sw.Write("\r\n");
                        }
                    }
                }

                return(true);
            }

            catch (Exception ex)
            {
                throw;
            }
        }