Пример #1
0
        //部门上传
        private void button5_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.textBox2.Text))
            {
                MessageBox.Show("请选择上传文件!", "系统提示");
                return;
            }
            //获得目录编号,其子文件,都在父编号添加数据
            var t = comboBox2.SelectedItem as Department;

            if (t != null)
            {
                if (comboBox2.SelectedItem as Department == null)
                {
                    return;
                }
                _depid = (comboBox2.SelectedItem as Department).DepartmentID;
                var fname = comboBox2.Text.Trim();
                _fname = fname;
                string aFirstName = this.textBox2.Text.Substring(this.textBox2.Text.LastIndexOf("\\") + 1, (this.textBox2.Text.LastIndexOf(".") - this.textBox2.Text.LastIndexOf("\\") - 1));   //文件名
                string aLastName  = this.textBox2.Text.Substring(this.textBox2.Text.LastIndexOf(".") + 1, (this.textBox2.Text.Length - this.textBox2.Text.LastIndexOf(".") - 1));               //扩展名
                byte[] tmpfile    = FileKit.GetFileData(this.textBox2.Text);
                File   file       = new File
                {
                    FileName       = aFirstName,
                    FileCreateTime = DateTime.Now,
                    FileExt        = aLastName,
                    FileData       = tmpfile,
                    FilePID        = -1,
                    FileSize       = tmpfile.Length,
                    UserID         = LoginUser.UserId
                };
                NewFileId = new FileBLL().AddFileDep(file, _depid);
                if (NewFileId > 0)
                {
                    _status           = "department";
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("文件添加失败!", "系统提示");
                }
            }
            else
            {
                MessageBox.Show("请选择对应目录!", "系统提示");
            }
        }
Пример #2
0
        public bool AddTemplate(string path, out DocType type)
        {
            type = DocType.Word;
            if (string.IsNullOrWhiteSpace(path))
            {
                return(false);
            }
            if (!System.IO.File.Exists(path))
            {
                return(false);
            }
            string fileName = path.Substring(path.LastIndexOf('\\') + 1);
            string fileExt  = fileName.Substring(fileName.LastIndexOf('.') + 1);

            switch (fileExt)
            {
            case "doc":
            case "docx":
                type = DocType.Word;
                break;

            case "ppt":
            case "pptx":
                type = DocType.PPT;
                break;

            case "xls":
            case "xlsx":
                type = DocType.Excel;
                break;
            }
            byte[]      data = FileKit.GetFileData(path);
            DocTemplete t    = new DocTemplete
            {
                TempleteName = fileName,
                TempleteExt  = fileExt,
                TempleteData = data,
                TempleteType = (int)type
            };

            return(Service.InsertTemplete(t));
        }