Ejemplo n.º 1
0
        /// <summary>
        /// 将字符串转换成byte[]数组,再依仕样指定长度截取值
        /// </summary>
        /// <param name="IfType"></param>
        /// <param name="seq"></param>
        /// <param name="aRecord"></param>
        /// <param name="FileEncoding"></param>
        public IF_PROD_PLAN SetRecordValues(string IfType, int seq, string[] arrayRecord, Encoding FileEncoding)
        {
            ComLibrary com = new ComLibrary();

            // 数据截取及默认数据的取得
            IF_PROD_PLAN ifpp = new IF_PROD_PLAN();

            //ifpp.IF_DATE = _if_date;                                                        //データ連携日
            //ifpp.IF_HMS = _if_hms;                                                          // 連携データ区分
            ifpp.IF_TYPE     = _if_type;                                                    //連携データ区分
            ifpp.IF_DATA_SEQ = seq;                                                         //データ順番
            ifpp.IF_PLAN_NO  = string.Empty;                                                //取込計画№
            ifpp.ITEM_NO     = ToDBC(arrayRecord.Length > 0 ? arrayRecord[0] : "").Trim();  //品目コード

            //ifpp.ITEM_DESC = ToDBC(arrayRecord.Length > 1 ? arrayRecord[1] : "").Trim();    //品目名称

            //ifpp.WS_CD = "";                                                                //作業区コード
            //ifpp.PLAN_YM = com.StringToInt(arrayRecord.Length > 2 ? arrayRecord[2].Replace("/", "") : "0");  //計画年月
            //ifpp.ORDER_QTY = com.StringToDouble(arrayRecord.Length > 3 ? arrayRecord[3] : "0");             //計画数量
            //ifpp.IF_DATA_FLAG = 0;                                                          //取込結果区分

            return(ifpp);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 指定目录下所有[CSV]类型文件导入DataTable
        /// XML方式一次性导入
        /// </summary>
        /// <returns></returns>
        public int ImpFilesToDataTableBulk()
        {
            int        rtn = 0;
            ComLibrary com = new ComLibrary();

            try
            {
                string   strFileNm = "";
                string[] strWk     = _file_path.Split('\\');
                strFileNm = strWk[strWk.Length - 1];
                string   strFileNmA = "";
                string[] strWkA     = strFileNm.Split('.');
                strFileNmA = strWkA[0];

                bool isEmpty = true;
                int  LineCnt = 0;

                string IfType = _if_type;//連携データ区分

                StringBuilder strXML = new StringBuilder();
                strXML.Append("<IFRows>");

                Boolean err_flag = false;
                //if (_save_path != "")
                //{
                //    if (_save_path.EndsWith("\\"))
                //        _save_file = _save_path + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_" + strFileNm;
                //    else
                //        _save_file = _save_path + "\\" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_" + strFileNm;

                //}
                // LOG FILE 名 2014.09.22
                //if (_log_path != "")
                //{
                //    if (_log_path.EndsWith("\\"))
                //        _log_file = _log_path + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_" + strFileNm;
                //    else
                //        _log_file = _log_path + "\\" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_" + strFileNm;
                //}

                // FILE COPY 2014.09.22
                //if (_save_path != "")
                //{
                //    File.Copy(_file_path, _save_file, true);
                //}

                Encoding FileEncoding = GetFileEncoding(_file_path);

                // 最初にメモリに読むこむ
                int wLineCnt = 0;

                StreamReader sr = new StreamReader(_file_path, FileEncoding);
                while (sr.Peek() >= 0)
                {
                    wLineCnt++;
                    string        strRecord = sr.ReadLine();
                    FileInfoClass fi        = new FileInfoClass();
                    fi.LineCnt = wLineCnt;
                    fi.Data    = strRecord;
                    lstFileInfo.Add(fi);
                }
                sr.Dispose();
                sr.Close();

                TextFieldParser parser = new TextFieldParser(_file_path, FileEncoding);
                using (parser)
                {
                    parser.TextFieldType = FieldType.Delimited;
                    parser.SetDelimiters(","); // 区切り文字はコンマ

                    while (!parser.EndOfData)
                    {
                        err_flag = false;
                        LineCnt++;
                        isEmpty = false;
                        string[] strRecord = parser.ReadFields(); // 1行読み込み 2014.09.22

                        string aRecord = "";
                        for (int p = 0; p < strRecord.Length; p++)
                        {
                            if (p > 0)
                            {
                                aRecord += "|";
                            }
                            aRecord += strRecord[p];
                        }
                        if (LineCnt <= lstFileInfo.Count)
                        {
                            ((FileInfoClass)lstFileInfo[LineCnt - 1]).CnvData = aRecord;
                        }

                        //各項目属性チェック
                        //年月, 数量
                        //if (!com.IsNumeric(strRecord[2].Replace("/", "")) || !com.IsNumeric(strRecord[3]))
                        //{
                        //    err_flag = true;

                        //    // 2014.10.10
                        //    if (LineCnt <= lstFileInfo.Count)
                        //    {
                        //        ((FileInfoClass)lstFileInfo[LineCnt - 1]).ErrFlag = 1;
                        //        ((FileInfoClass)lstFileInfo[LineCnt - 1]).ErrMsg = "数値エラー。";
                        //    }
                        //}

                        //数据各项值取得
                        IF_PROD_PLAN ifpl = SetRecordValues(IfType, LineCnt, strRecord, FileEncoding);


                        //if (ifpl.ITEM_NO.ToString().Length > 30
                        //|| ifpl.ITEM_DESC.ToString().Length > 50
                        //|| ifpl.PLAN_YM.ToString().Length > 6
                        //|| com.StringToDouble(ifpl.ORDER_QTY.ToString()) > 1000000000)
                        //{
                        //    err_flag = true;

                        //    if (LineCnt <= lstFileInfo.Count)
                        //    {
                        //        ((FileInfoClass)lstFileInfo[LineCnt - 1]).ErrFlag = 1;
                        //        ((FileInfoClass)lstFileInfo[LineCnt - 1]).ErrMsg += "桁数エラー。";
                        //    }
                        //}


                        if (err_flag)   // 2014.10.10
                        {
                            //_len_err_cnt++;

                            ////IF 取込データログに登録
                            //Poif poif = new Poif(_chg_user_id, _lang);
                            //Message msg = new Message(_chg_user_id, _lang);

                            //poif.if_date = ifpl.IF_DATE;
                            //poif.if_hms = ifpl.IF_HMS;
                            //poif.if_type = ifpl.IF_TYPE;
                            //poif.if_type_name = _if_type_name;
                            //poif.if_data_seq = ifpl.IF_DATA_SEQ;
                            //poif.if_data = aRecord;
                            //poif.if_data_err = msg.GetMessage("COLUMN_LENGTH_FORMAT_ERR");
                            //poif.if_data_flag = 2;
                            //poif.chg_pgm = _chg_pgm;
                            //poif.chg_user_id = _chg_user_id;
                            //poif.lang = _lang;
                            //poif.errcode = _errcode;
                            //poif.errmsg = _errmsg;
                            //poif.sqlcode = _sqlcode;
                            //poif.dbmsg = _dbmsg;

                            //rtn = poif.Ins_IF_IN_LOG();
                            //if (rtn == ComConst.FAILED)
                            //{
                            //    goto RESULT;
                            //}
                        }

                        if (!err_flag)  // 2014.09.22
                        {
                            //XML格式作成
                            strXML.Append("<IFRow ");
                            //strXML.Append(" IF_DATE=\"" + ifpl.IF_DATE.ToString() + "\"");
                            //strXML.Append(" IF_HMS=\"" + ifpl.IF_HMS.ToString() + "\"");
                            strXML.Append(" IF_TYPE=\"" + ifpl.IF_TYPE + "\"");
                            strXML.Append(" IF_DATA_SEQ=\"" + ifpl.IF_DATA_SEQ.ToString() + "\"");
                            strXML.Append(" IF_PLAN_NO=\"" + ifpl.IF_PLAN_NO + "\"");
                            strXML.Append(" ITEM_NO=\"" + ifpl.ITEM_NO + "\"");
                            //strXML.Append(" ITEM_DESC=\"" + com.XMLString(ifpl.ITEM_DESC) + "\"");
                            //strXML.Append(" WS_CD=\"" + ifpl.WS_CD + "\"");
                            //strXML.Append(" PLAN_YM=\"" + ifpl.PLAN_YM.ToString() + "\"");
                            //strXML.Append(" ORDER_QTY=\"" + ifpl.ORDER_QTY.ToString() + "\"");
                            //strXML.Append(" IF_DATA_FLAG=\"" + ifpl.IF_DATA_FLAG.ToString() + "\"");
                            //strXML.Append(" CHG_PGM=\"" + _chg_pgm + "\"");
                            strXML.Append(" CHG_USER_ID=\"" + _chg_user_id + "\"");
                            strXML.Append(" />");
                        }
                    }
                }
                strXML.Append("</IFRows>");

                //_file_line_cnt = LineCnt;

                if (isEmpty)
                {
                    Message msg = new Message(_chg_user_id, _lang);
                    _strErr = msg.GetMessage("FILE_NOT_EXIST_ERR");
                    rtn     = ComConst.CHECK_ERROR;
                    goto RESULT;
                }
                else
                {
                    // [IF初期取込生産計画]の一括登録
                    #region : [IF初期取込生産計画]の一括登録
                    ComDB db = new ComDB(_db_type);
                    db.DbParametersClear();

                    db.DbPsetInt("rtn", rtn, ComConst.DB_RTN);
                    db.DbPsetXml("@I_XML", strXML.ToString(), strXML.ToString().Length, ComConst.DB_IN);
                    db.DbPsetInt("@I_LANG", _lang, ComConst.DB_IN);
                    db.DbPsetInt("@O_ERRCODE", _errcode, ComConst.DB_OUT);
                    db.DbPsetString("@O_MSG", _errmsg, ComConst.DB_OUT);
                    db.DbPsetInt("@O_SQLCODE", _sqlcode, ComConst.DB_OUT);
                    db.DbPsetString("@O_SQLMSG", _dbmsg, ComConst.DB_OUT);
                    db.DbPsetString("@O_PROC_NAME", _proc_name, ComConst.DB_OUT);

                    db.DbBeginTrans();
                    rtn = db.DbStored("SP_IF_PROD_PLAN_BULK_IMP");//一括登録
                    if (rtn == ComConst.SUCCEED)
                    {
                        db.DbCommit();
                    }
                    else
                    {
                        db.DbRollback();
                        rtn = db.DbPgetInt("rtn");
                        if (rtn > 0)
                        {
                            _errcode   = db.DbPgetInt("@O_ERRCODE");
                            _errmsg    = db.DbPgetString("@O_MSG");
                            _sqlcode   = db.DbPgetInt("@O_SQLCODE");
                            _dbmsg     = db.DbPgetString("@O_SQLMSG");
                            _proc_name = db.DbPgetString("@O_PROC_NAME");
                            _strErr    = _errcode + ":" + _errmsg + "[" + _sqlcode + ":" + _dbmsg + "(" + _proc_name + ")]";
                        }
                        else
                        {
                            _strErr = db.strErr;
                        }
                        rtn = ComConst.FAILED;
                    }
                    #endregion
                }
                //File.Delete(_file_path);
            }
            catch (Exception ex)
            {
                _strErr = ex.ToString();
                rtn     = ComConst.FAILED;
            }

RESULT:
            return(rtn);
        }