Exemple #1
0
        public static string UploadFile2ServerUploadFolder(System.Web.UI.Page page, System.Web.UI.HtmlControls.HtmlInputFile inputFile, string serverFilefullPath)
        {
            if (inputFile.PostedFile == null)
            {
                return(null);
            }

            if (inputFile.PostedFile.FileName.Trim() == string.Empty)
            {
                return(null);
            }

            if (inputFile.PostedFile.ContentLength > 1048576)
            {
                throw new RemotingException(ErrorCenter.GetErrorServerDescription(typeof(BOMFileParser), ErrorCenter.ERROR_UPLOAD_UPPERLIMIT));
            }

            string[] filePath = inputFile.PostedFile.FileName.Split(new char[] { CHAR_SEPARATOR });
            string   fileName = page.Request.PhysicalApplicationPath + FILE_UPLOAD_PATH + System.Guid.NewGuid().ToString().Substring(0, 8) + filePath[filePath.Length - 1];

            if (serverFilefullPath != null)
            {
                fileName = serverFilefullPath;
            }

            try
            {
                //check the folder exist ,if no ,create it
                //add by crystal chu 20050404
                if (!System.IO.Directory.Exists(page.Request.PhysicalApplicationPath + FILE_UPLOAD_PATH))
                {
                    System.IO.Directory.CreateDirectory(page.Request.PhysicalApplicationPath + FILE_UPLOAD_PATH);
                }
                inputFile.PostedFile.SaveAs(fileName);
            }
            catch (Exception ex)
            {
                //_log.Error(ex.Message,ex);
                throw new RemotingException(ErrorCenter.GetErrorServerDescription(typeof(BOMFileParser), ErrorCenter.SYSTEM_ERROR), ex);
            }

            return(fileName);
        }
Exemple #2
0
        public static object[] ProcessFile(string logFile, bool inHead, string logUser)
        {
            if (!System.IO.File.Exists(logFile))
            {
                return(null);
            }

            string    line     = null;
            ArrayList lineList = new ArrayList();

            StreamReader streamReader = null;

            try
            {
                streamReader = new StreamReader(logFile, System.Text.Encoding.GetEncoding("GB2312"));
                line         = streamReader.ReadLine().Trim();

                if (!inHead)
                {
                    line = streamReader.ReadLine().Trim();
                }

                // TODO: 开始或中间有空行的处理
                while ((line != null) && (line != ""))
                {
                    lineList.Add(ProcessFileLine(line, logUser));
                    line = streamReader.ReadLine();
                }
            }
            catch (Exception ex)
            {
                //_log.Error(ex.Message,ex);
                throw new RemotingException(ErrorCenter.GetErrorServerDescription(typeof(BOMFileParser), ErrorCenter.SYSTEM_ERROR), ex);
            }
            object[] sboms = new object[lineList.Count];
            for (int i = 0; i < lineList.Count; i++)
            {
                sboms[i] = lineList[i];
            }

            return(sboms);
        }
Exemple #3
0
        /// <summary>
        /// 标准Bom的location的","用";"替换,得到标准每行字符串
        /// </summary>
        /// <param name="mostring"></param>
        /// <returns></returns>
        private static string GetFormatMOString(string mostring)
        {
            int    leftpostion = mostring.IndexOf(',');
            string newmostring = string.Empty;

            if (leftpostion != -1)
            {
                string leftstr      = mostring.Substring(0, leftpostion);
                int    rightpostion = mostring.IndexOf(',', leftpostion + 1);
                if (rightpostion == -1)
                {
                    throw new RemotingException(ErrorCenter.GetErrorServerDescription(typeof(BOMFileParser), ErrorCenter.ERROR_CREATENEWREWORKMOCODE));
                }
                string origstring = mostring.Substring(leftpostion, rightpostion - leftpostion + 1);
                string newstring  = origstring.Replace(',', ';');
                newmostring = mostring.Replace(origstring, newstring);
                return(newmostring);
            }
            else
            {
                return(mostring);
            }
        }
Exemple #4
0
        public static SBOM  ProcessFileLine(string lineContent, string logUser)
        {
            char[] splitChar = new char[1];
            splitChar[0] = CHAR_SEPARATOR_COMMA;

            string[] lineColumn = null;
            lineColumn = lineContent.Split(splitChar);

            if (lineColumn.Length < FILE_COLUMN_SIZE)
            {
                throw new RemotingException(ErrorCenter.GetErrorServerDescription(typeof(BOMFileParser), ErrorCenter.FILE_COLUMN_ERROR));
            }

            if (lineColumn[1].ToString().Trim() == string.Empty)
            {
                throw new RemotingException("1" + ErrorCenter.GetErrorServerDescription(typeof(BOMFileParser), ErrorCenter.NOT_EMPTY_ERROR));
            }

            if (lineColumn[2].ToString().Trim() == string.Empty)
            {
                throw new RemotingException("2" + ErrorCenter.GetErrorServerDescription(typeof(BOMFileParser), ErrorCenter.NOT_EMPTY_ERROR));
            }

            if (lineColumn[3].ToString().Trim() == string.Empty)
            {
                throw new RemotingException("3" + ErrorCenter.GetErrorServerDescription(typeof(BOMFileParser), ErrorCenter.NOT_EMPTY_ERROR));
            }

            if (lineColumn[4].ToString().Trim() == string.Empty)
            {
                throw new RemotingException("4" + ErrorCenter.GetErrorServerDescription(typeof(BOMFileParser), ErrorCenter.NOT_EMPTY_ERROR));
            }

            SBOM sbom = new SBOM();

            try
            {
                sbom.Sequence = Int32.Parse(lineColumn[0].ToString());
            }
            catch
            {
                sbom.Sequence = 0;
            }
            sbom.SBOMItemECN           = lineColumn[1].ToString().Trim();
            sbom.ItemCode              = lineColumn[2].ToString().Trim();
            sbom.SBOMItemCode          = lineColumn[3].ToString().Trim().ToUpper();
            sbom.SBOMItemName          = lineColumn[4].ToString().Trim();
            sbom.SBOMItemLocation      = lineColumn[7].ToString().Trim();
            sbom.SBOMItemStatus        = ITEM_STATUS_NORMAL;
            sbom.SBOMItemEffectiveDate = FormatHelper.TODateInt(lineColumn[5].ToString().Trim());
            sbom.SBOMItemEffectiveTime = 0;
            sbom.SBOMItemInvalidDate   = FormatHelper.TODateInt(lineColumn[6].ToString().Trim());;
            sbom.SBOMItemInvalidTime   = 235959;
            sbom.SBOMItemQty           = 0;
            sbom.SBOMItemControlType   = ITEM_CONTROL_LOT;
            sbom.MaintainUser          = logUser;
            sbom.MaintainDate          = FormatHelper.TODateInt(DateTime.Today);
            sbom.MaintainTime          = FormatHelper.TOTimeInt(DateTime.Now);
            sbom.OrganizationID        = GlobalVariables.CurrentOrganizations.First().OrganizationID;

            if (sbom.SBOMItemInvalidDate < sbom.SBOMItemEffectiveDate)
            {
                throw new RemotingException(ErrorCenter.GetErrorServerDescription(typeof(BOMFileParser), ErrorCenter.EFFECTDATE_ERROR));
            }
            if (FormatHelper.TODateInt(DateTime.Today) >= sbom.SBOMItemInvalidDate)
            {
                throw new RemotingException(ErrorCenter.GetErrorServerDescription(typeof(BOMFileParser), ErrorCenter.INEFFECTDATE_ERROR));
            }
            return(sbom);
        }