1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CY.BLL.EC;
using CY.Model;
using CY.BLL.Sys;
using CY.Infrastructure.Common;
using CY.BLL;
using CY.Model.Inquiry;
using CY.BLL.OA;
using CY.Infrastructure.Query;
using CY.WebForm.Pages.common;
using System.IO;
 
 
namespace FileUpload
{
    public partial class FileUpload : System.Web.UI.Page
    {
        LF_OrderFileBLL _lF_OrderFileBLL = null;
        EC_OrderBasicBLL _eC_OrderBasicBLL = null;
        EC_MemberBasicBLL _eC_MemberBasicBLL = null;
 
        int strOrderid
        {
            get
            {
                return Convert.ToInt32(Request["orderid"]);
            }
        }
 
        public FileUpload()
        {
            _lF_OrderFileBLL = new LF_OrderFileBLL();
            _eC_OrderBasicBLL = new EC_OrderBasicBLL();
            _eC_MemberBasicBLL = new EC_MemberBasicBLL();
 
            //strOrderid = 0;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
            }
        }
 
        protected void Upload_Click(object sender, EventArgs e)
        {
            string FileName = this.AttachFile.FileName;//获取上传文件的全路径
            string ExtenName = System.IO.Path.GetExtension(FileName);//获取扩展名
            if (Directory.Exists(Server.MapPath("~/UpLoads/")) == false)
            {
                Directory.CreateDirectory(Server.MapPath("~/UpLoads/"));
            }
            
            string SaveFileName = System.IO.Path.Combine(Server.MapPath("~/UpLoads/"), DateTime.Now.ToString("yyyyMMddHHmmfff") + ExtenName);//合并两个路径为上传到服务器上的全路径
            if (this.AttachFile.ContentLength > 0)
            {
                try
                {
                    //获取订单文件表
                    LF_OrderFile mode = new LF_OrderFile();
                    EC_OrderBasic _eC_OrderBasic = _eC_OrderBasicBLL.SelectModelById(strOrderid);
              
                    bool isSuccess = false;
                    if (null == _eC_OrderBasic)
                    {
                        CY.WebForm.BasePage.JavaScript.MessageBox("数据不存在!", this);
                    }
                    else
                    {
                        if (_eC_OrderBasic.OutId > 0)
                        {
                            _eC_OrderBasic = _eC_OrderBasicBLL.SelectModelById(Convert.ToInt32(_eC_OrderBasic.OutId));
                            mode.OrderId = Convert.ToInt32(_eC_OrderBasic.Keyid);
                        }
                        else
                        {
                            mode.OrderId = strOrderid;
                        }
                    }
                    mode.FileName = FileName;
                    mode.FilePath = SaveFileName;
                    mode.FileSize = ((AttachFile.ContentLength)/1024)/1024;
                    mode.FileType = ExtenName;
                    mode.FileState = 0;
                    mode.UploadTime = DateTime.Now;
                    mode.UploaderId = _eC_OrderBasic.BuyerId;
                    mode.SellerId = _eC_OrderBasic.SellerId;
 
                    //mode.ImpactTime = DateTime.Now;
 
                    //获取厂商并更新实体
                    EC_FirmInfo _eC_FirmInfo = _eC_MemberBasicBLL.GetFirmInfoByMemberId(_eC_OrderBasic.SellerId);
                    int iFileSize = 0;
                    iFileSize = Convert.ToInt32(_eC_FirmInfo.FileSize) - Convert.ToInt32(mode.FileSize);
                    //_eC_FirmInfo.FileSize = iFileSize;
 
                   // float FileSize = (float)System.Math.Round((float)AttachFile.ContentLength / 1024000, 1);
                    if (iFileSize < 0)
                    {
                        Response.Write("<script>alert('对不起,卖家的文件空间不足,请联系卖家')</script>");
                        pbProgressBar.Style.Add("display", "none");
                        return;
                    }
                    else
                    {
                        this.AttachFile.MoveTo(SaveFileName, Brettle.Web.NeatUpload.MoveToOptions.Overwrite);
                    }         
                    isSuccess = _lF_OrderFileBLL.AddOrderFiles(_eC_FirmInfo,mode);
                    if (isSuccess)
                    {
                        //CY.WebForm.BasePage.JavaScript.MessageBox("添加成功", this);
                        CY.WebForm.BasePage.JavaScript.RefreshParent(this);
 
                    }
                    
 
                }
                catch (Exception ex)
                {
                    CY.WebForm.BasePage.JavaScript.MessageBox("上传失败", this);
                    throw ex;
                }
            }
 
        }
    }
}