Exemple #1
0
        /// <summary>
        /// 匯入檔案
        /// </summary>
        /// <param name="s_FilePathName"></param>
        /// <param name="DBT"></param>
        /// <returns></returns>
        private bool ImportDocument(string s_FilePathName, System.Data.Common.DbTransaction DBT)
        {
            #region
            bool bResult = false;
            try
            {
                string strStore = "", strRoute = "", strStep = "", strOldStore = "", strStAcceptDate = "", strQtyBoxNum = "", strLoginId = "VDS2G";
                ArrayList ParameterList = new ArrayList();
                Int32 iQtyBoxNum = 0;
                STMModel.VDS_STM34_BCO BCO = new STMModel.VDS_STM34_BCO(ConnnectionString);
                Int32 i32ID = 0;
                //一行一行的取讀取文字檔內的資料  System.Text.Encoding.Default才不會讀到亂碼
                StreamReader stmRdr = new StreamReader(s_FilePathName, System.Text.Encoding.Default);
                string line = "";
                while (line != null)
                {
                    strStore = "";
                    strRoute = "";
                    strStep = "";
                    strOldStore = "";
                    strStAcceptDate = "";
                    strQtyBoxNum = "";
                    ParameterList.Clear();
                    
                    System.Diagnostics.Debug.WriteLine(line);

                    line = stmRdr.ReadLine();

                    if (line != null)
                    {
                        if (line.Length > 0)
                        {
                            if (line.Length == 29)
                            {
                                strStore = line.Substring(0, 6);
                                strRoute = line.Substring(6, 3);
                                strStep = line.Substring(9, 3);
                                strOldStore = line.Substring(12, 6);
                                strStAcceptDate = line.Substring(18, 8);
                                strQtyBoxNum = line.Substring(26, 3);
                                Int32.TryParse(strQtyBoxNum, out iQtyBoxNum);

                                ParameterList.Add(strStore);
                                ParameterList.Add(strRoute);
                                ParameterList.Add(strStep);
                                ParameterList.Add(strOldStore);
                                ParameterList.Add(strStAcceptDate);
                                ParameterList.Add(iQtyBoxNum);
                                ParameterList.Add(strLoginId);

                                i32ID = BCO.LibraryDistributeImport(ParameterList, DBT);

                                bResult = true;
                            }
                            else
                            {
                                throw new Exception("資料長度不足");
                            }
                        }
                    }
                }

                stmRdr.Close();
                stmRdr.Dispose();
            }
            catch(Exception ex)
            {
                throw ex;
            }

            return bResult;
            #endregion
        }
Exemple #2
0
        /// <summary>
        /// 輸入處理
        /// </summary>
        /// <returns>回傳作業成功失敗</returns>
        public bool Input()
        {
            #region
            bool bResult = false;
            try
            {
                string strCurrentSeq = "", strNextSeq = "", strNextFileName = "";

                STMModel.VDS_STM34_BCO BCO = new STMModel.VDS_STM34_BCO(ConnnectionString);
                System.Data.Common.DbTransaction DBT = BCO.OpenAndGetConnection(ConnnectionString).BeginTransaction();
                
                try
                {
                    for (Int32 i = 1; i <= 99; i++)
                    {

                        bResult = ImportDocument(File_Path_Name.Replace(".ok", ""), DBT);

                        //檢查是否還有檔案
                        strCurrentSeq = (i).ToString().PadLeft(2, Char.Parse("0"));
                        strNextSeq = (i + 1).ToString().PadLeft(2, Char.Parse("0"));
                        strNextFileName = string.Format("{0}{1}.delivery.ok", File_Name, strNextSeq);

                        if (!File.Exists(string.Format("{0}\\{1}", File_Path_IN, strNextFileName)))
                        {
                            break;
                        }
                        else
                        {
                            File_Path_Name = File_Path_Name.Replace(strCurrentSeq + ".delivery", strNextSeq + ".delivery");
                        }
                    }

                    DBT.Commit();//交易成功

                }
                catch (Exception ex)
                {
                    DBT.Rollback();//交易失敗
                    throw ex;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return bResult;

            #endregion
        }