コード例 #1
0
ファイル: SSpaceBC.cs プロジェクト: wanghouxian2015/GMWJGit
        /// <summary>
        /// �����ļ��ϴ�
        /// </summary>
        /// <param name="model">sFile��model</param>
        /// <param name="postedFile">�ļ�</param>
        /// <param name="empId">��ԱId</param>
        /// <param name="isImg">�Ƿ�ͼƬ</param>
        /// <returns>��û�����򷵻�true�����򷵻�false</returns>
        public int UploadFile(SFileData model, HttpPostedFile postedFile, int empId, bool isImg)
        {
            int ret;
            string saveFilePathNm = "";
            string saveFilePath = "";
            string saveUrlPath = "";
            string nowDt = "";
            nowDt = DateTime.Now.ToString("yyyy-MM-dd");

            SSystemConfigBB systemConfigBB = new SSystemConfigBB();
            DataSet systemConfigDs = new DataSet();
            SFileSaveTypeBB fileSaveTypeBB = new SFileSaveTypeBB();
            DataSet fileSaveTypeDs = new DataSet();

            try
            {
                //��ȡϵͳ���������ϴ��������ߴ磨KB)
                systemConfigDs = systemConfigBB.GetList("");
                if (systemConfigDs.Tables[0].Rows.Count == 0)
                {
                    throw new Exception("�����Ƚ���ϵͳ���ã�");
                }
                DataRow systemConfigRow = systemConfigDs.Tables[0].Rows[0];

                int maxSizeK = Convert.ToInt32(systemConfigRow["maxUpFileSize"]);
                int maxSize = maxSizeK * 1024;
                model.fileSize = postedFile.ContentLength;
                if (model.fileSize > maxSize)
                {
                    throw new Exception("��ǰ�ϴ��ļ��ijߴ����׼������ߴ�,��ѹ����" + maxSizeK + "KB���ڽ����ϴ�!");
                }

                //��ȡupFile���ļ�����·��������
                fileSaveTypeDs = fileSaveTypeBB.GetList("typeNo='upFile'");
                if (fileSaveTypeDs.Tables[0].Rows.Count == 0)
                {
                    throw new Exception("�����������ļ�����·����");
                }
                DataRow fileSaveTypeRow = fileSaveTypeDs.Tables[0].Rows[0];

                saveFilePath = fileSaveTypeRow["absolutePath"].ToString();
                saveFilePath = AddAbsoluteLastSeparator(saveFilePath);
                saveUrlPath = fileSaveTypeRow["urlPath"].ToString();
                saveUrlPath = AddRelativeLastSeparator(saveUrlPath);

                FileInfo preFileInfo = new FileInfo(postedFile.FileName);

                //��ȡ�ļ����
                //2015-06-30 �޸� �����浽��̨�����Ƹ�Ϊԭ��������
                //string fileName = this.fileBB.GetNewFileName("upFile", nowDt, empId);
                //��ȡԭ�ļ���չ��
               // fileName += preFileInfo.Extension;

                saveFilePath += Convert.ToString(empId) + Path.DirectorySeparatorChar;
                saveFilePath += nowDt + Path.DirectorySeparatorChar;

                saveUrlPath += empId + "/";
                saveUrlPath += nowDt + "/";
                DirectoryInfo dir = new DirectoryInfo(saveFilePath);
                if (!dir.Exists)
                {
                    dir.Create();
                }

                //�����ļ����ļ��б��¼
                saveFilePathNm = saveFilePath + preFileInfo.Name;

                model.typeNo = "upFile";
                model.preFileNm = preFileInfo.Name;
               // model.sysFileNm = fileName;
                model.sysFileNm = preFileInfo.Name;//2015-06-26�޸� ����������������Ϊһ��
                model.urlPath = saveUrlPath;
                model.absolutPath = saveFilePath;
                model.usingNum = 1;
                model.useEmpId = empId;
                model.isrtEmpId = empId;
                model.isrtDt = nowDt;

                postedFile.SaveAs(saveFilePathNm);

                ret = this.fileBB.AddRecord(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                systemConfigBB.Dispose();
                fileSaveTypeBB.Dispose();
            }
            return ret;
        }
コード例 #2
0
ファイル: SSpaceBC.cs プロジェクト: wanghouxian2015/GMWJGit
        /// <summary>
        /// �����ļ��ϴ�
        /// </summary>
        /// <param name="model">sFile��model</param>
        /// <param name="postedFile">�ļ�</param>
        /// <param name="saveType">�ļ���������</param>
        /// <param name="empId">��ԱId</param>
        /// <param name="isImg">�Ƿ�ͼƬ</param>
        /// <returns>��û�����򷵻�true�����򷵻�false</returns>
        public int UploadCustFile(SFileData model, HttpPostedFile postedFile, string saveType, int empId, bool isImg,string filenm)
        {
            int ret;
            string saveFilePath = "";
            string saveUrlPath = "";
            string nowDt = "";
            nowDt = DateTime.Now.ToString("yyyy-MM-dd");

            SSystemConfigBB systemConfigBB = new SSystemConfigBB();
            DataSet systemConfigDs = new DataSet();
            SFileSaveTypeBB fileSaveTypeBB = new SFileSaveTypeBB();
            DataSet fileSaveTypeDs = new DataSet();

            try
            {
                //��ȡϵͳ���������ϴ��������ߴ磨KB)
                systemConfigDs = systemConfigBB.GetList("");
                if (systemConfigDs.Tables[0].Rows.Count == 0)
                {
                    throw new Exception("�����Ƚ���ϵͳ���ã�");
                }
                DataRow systemConfigRow = systemConfigDs.Tables[0].Rows[0];

                int maxSizeK = Convert.ToInt32(systemConfigRow["maxUpFileSize"]);
                int maxSize = maxSizeK * 1024;
                model.fileSize = postedFile.ContentLength;
                if (model.fileSize > maxSize)
                {
                    throw new Exception("��ǰ�ϴ��ļ��ijߴ����׼������ߴ�,��ѹ����" + maxSizeK + "KB���ڽ����ϴ�!");
                }

                //��ȡupFile���ļ�����·��������
                fileSaveTypeDs = fileSaveTypeBB.GetList("typeNo='" + saveType + "'");
                if (fileSaveTypeDs.Tables[0].Rows.Count == 0)
                {
                    throw new Exception("�����������ļ�����·����");
                }
                DataRow fileSaveTypeRow = fileSaveTypeDs.Tables[0].Rows[0];

                saveFilePath = fileSaveTypeRow["absolutePath"].ToString()+"/";

                saveUrlPath = fileSaveTypeRow["urlPath"].ToString() + "/";

                ;
                DirectoryInfo dir = new DirectoryInfo(saveFilePath);
                if (!dir.Exists)
                {
                    dir.Create();
                }

                //�����ļ����ļ��б��¼

                model.typeNo = saveType;
                model.preFileNm = filenm;
                model.sysFileNm = filenm;
                model.urlPath = saveUrlPath;
                model.absolutPath = saveFilePath;
                model.usingNum = 1;
                model.useEmpId = empId;
                model.isrtEmpId = empId;
                model.isrtDt = nowDt;

                postedFile.SaveAs(saveFilePath+filenm);

                ret = this.fileBB.AddRecord(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                systemConfigBB.Dispose();
                fileSaveTypeBB.Dispose();
            }
            return ret;
        }