username@email.com
2021-09-22 1bfc8f9c7baad9be7fdb92742cf796f9fdb50df3
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
using CY.Infrastructure.Common;
using CY.Infrastructure.Logging;
using CY.SQLDAL;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using static CY.WebForm.MainPage;
using CY.Model.OA;
using CY.WebForm.Helper;
using CY.Infrastructure.Query;
using System.IO;
 
namespace CY.WebForm.Pages.business
{
    public partial class CorporateClientsUpLoadContract : BasePage
    {
 
        
        /// <summary>
        /// 选择文件
        /// </summary>
        List<HttpFileCollection> SelFile { set; get; }
        /// <summary>
        /// 合同附件集合
        /// </summary>
        List<OA_CorporateClientsContract> fileDataList { set; get; } = new List<OA_CorporateClientsContract>();
        /// <summary>
        /// 附件个数
        /// </summary>
        public int  FileCount { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            UCPager1.AspNetPager.PageSize=5;
            UCPager1.AspNetPager.PageChanged += AspNetPager1_PageChanged;
 
            
            
                if (Request["deleteKeyIds"] != null)
            {
                //删除页面
                string  keyid = Request["deleteKeyIds"].ToString();
                Database DC = new Database();
                string  sqlStr = string.Format(@"USE [ECTEST] SELECT[Keyid]      ,[CorporateClientsid]       ,[CorporateClientsName]       ,[FileName]       ,[PageCode]       ,[FilePath]       ,[Remark]     FROM[dbo].[OA_CorporateClientContract] where Keyid='{0}'ORDER BY PageCode ", keyid);
 
                
                try
                {
                    SqlCommand myCmd = new SqlCommand(sqlStr, DC.Connection);
                    //SqlDataAdapter myDa = new SqlDataAdapter(myCmd);
                    var a = myCmd.ExecuteReader();
                    //myDa.Dispose();
                    fileDataList = new List<OA_CorporateClientsContract>();
                    OA_CorporateClientsContract Contract;
                    while (a.Read())
                    {   //注意如何将每次读取到的记录添加到listbox1中(因为第一次做时出错了,嘿嘿)
                        Contract = new OA_CorporateClientsContract();
                        Contract.Keyid = a.GetGuid(0);
                        Contract.CorporateClientsid = a.GetGuid(1);
                        Contract.CorporateClientsName = a.GetString(2);
                        Contract.FileName = a.GetString(3);
                        Contract.PageCode = a.GetInt32(4);
                        Contract.FilePath = a.GetString(5);
                        Contract.Remark = a.GetString(6);
 
 
                        fileDataList.Add(Contract);
                    }
                    a.Close();     //关闭sqldatareader
                    if (fileDataList.Count > 0)
                    { FileInfo file = new FileInfo(Server.MapPath(fileDataList[0].FilePath));//指定文件路径
                        if (file.Exists)//判断文件是否存在
                        {
                            file.Attributes = FileAttributes.Normal;//将文件属性设置为普通,比方说只读文件设置为普通
                            file.Delete();//删除文件
                        }
                    }
                    sqlStr = string.Format(@"USE [ECTEST]DELETE FROM [dbo].[OA_CorporateClientContract] where Keyid='{0}'", keyid);
                    myCmd = new SqlCommand(sqlStr, DC.Connection);
                    myCmd.ExecuteNonQuery();
                    JavaScript.MessageBox("删除成功",this);
                  //  Response.Redirect("/Pages/business/CorporateClientsUpLoadContract.aspx");
                }
                catch (Exception ee)
                {
                    new Log4NetAdapter().Log("查找合同出错:" + ee.Message);
                    JavaScript.MessageBox("删除失败", this);
 
                }
                finally
                {
                    if (DC.Connection.State != System.Data.ConnectionState.Closed)
                        DC.Connection.Close();
                }
 
            }
            if (!IsPostBack)
                BindList();
            
        }
 
        //绑定列表
        private void BindList()
        {
 
             
            Pagination pa = new Pagination();
            pa.PageSize = UCPager1.AspNetPager.PageSize;
            pa.PageIndex = UCPager1.AspNetPager.CurrentPageIndex;
            Guid Keyid = Request["Keyid"].ToGuid2();
        
               if(Keyid==null)
            {
                JavaScript.MessageBox("未找到该客户", this, false, false);
                return;
            }
            Database DC = new Database();
            string sqlStr =string.Format(@"USE [ECTEST]    select * from (select ROW_NUMBER() OVER(Order by PageCode) AS RowNumber,* from [dbo].[OA_CorporateClientContract] where CorporateClientsid='{0}' ) as b where b.RowNumber BETWEEN ({1}-1)*({2})+1 and {1}*{2} order by PageCode  ", Keyid,pa.PageIndex,pa.PageSize);
            int count = 0;
            try
            {
                SqlCommand myCmd = new SqlCommand(sqlStr, DC.Connection);
                //SqlDataAdapter myDa = new SqlDataAdapter(myCmd);
                var  a = myCmd.ExecuteReader();
                //myDa.Dispose();
                fileDataList = new List <OA_CorporateClientsContract>(); 
                OA_CorporateClientsContract Contract ;
                while (a.Read())
                {   //注意如何将每次读取到的记录添加到listbox1中(因为第一次做时出错了,嘿嘿)
                    Contract = new OA_CorporateClientsContract();
                    Contract.Keyid = a.GetGuid(1);
                    Contract.CorporateClientsid = a.GetGuid(2);
                    Contract.CorporateClientsName = a.GetString(3);
                    Contract.FileName = a.GetString(4);
                    Contract.PageCode = a.GetInt32(5);
                    Contract.FilePath = a.GetString(6);
                    Contract.Remark = a.GetString(7);
 
 
                    fileDataList.Add(Contract);
                }
                a.Close();     //关闭sqldatareader
                sqlStr = string.Format("select  count(*) from [dbo].[OA_CorporateClientContract] where CorporateClientsid='{0}'", Keyid);
                myCmd = new SqlCommand(sqlStr, DC.Connection);
                count = (int)myCmd.ExecuteScalar();
 
 
            }
            catch (Exception ee)
            {
                new Log4NetAdapter().Log("查找合同出错:" + ee.Message);
 
            }
            finally
            {
                if (DC.Connection.State != System.Data.ConnectionState.Closed)
                    DC.Connection.Close();
            }
 
 
 
            FileCount = fileDataList.Count;
 
            this.RepClientList.DataSource = fileDataList;// fileDataList.AsEnumerable<OA_CorporateClientsContract>();
 
            this.RepClientList.DataBind();
 
            UCPager1.AspNetPager.RecordCount = count;
        }
        //分页事件
        protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {
            BindList();
        }
 
        protected void btn_Submit_Click(object sender, EventArgs e)
        {
        
            var files = Request.Files;
            if (files.Count <= 0)
                return;
            HttpPostedFile postedFile = files[0];           
            if (postedFile.ContentLength == 0)
                return;
            Guid? g = GetContractFileID();
            upLoadContractFile uploadContract = new upLoadContractFile();
            if (g != null)
            {
                try
                {
                    uploadContract.SavAndUpDataContractFile(postedFile,CountractFileKeiId :g);
 
                    JavaScript.MessageBox("上传文件成功", this);
                    //JavaScript.RefreshSelf(this);
                    //JavaScript.RefreshOpener(this);
                    BindList();
                }
                catch (Exception)
                {
                    JavaScript.MessageBox("上传文件失败", this);
                    // JavaScript.RefreshSelf(this);
                    //JavaScript.RefreshOpener(this);
                    BindList();
 
                }
                return;
            }
          
            //新建走下面页面
            OA_CorporateClientsContract contract = new OA_CorporateClientsContract
            {
                CorporateClientsid = Request["Keyid"].ToGuid2(),
                FileName = System.IO.Path.GetFileName(postedFile.FileName),
                PageCode = Convert.ToInt32(this.TextPage.Value),
                Creater= CurrentUser.TrueMemberId,
 
            };
 
 
 
            try
            {
                uploadContract.SavAndUpDataContractFile(postedFile, contract);
             
                JavaScript.MessageBox("上传文件成功", this);
                //JavaScript.RefreshSelf(this);
                //JavaScript.RefreshOpener(this);
                BindList();
            }
            catch (Exception )
            {
                JavaScript.MessageBox("上传文件失败", this);
                // JavaScript.RefreshSelf(this);
                //JavaScript.RefreshOpener(this);
                BindList();
 
            }
            
 
            //    CY.WebForm.cs.UploadCS.Upload(System.Web.HttpContext.Current.Request.MapPath("contractImgs/") + Guid.NewGuid().ToString() + fileName)
 
 
            //var files = Request.Files;
            //for (int iFile = 0; iFile < files.Count; iFile++)
            //{
            //    ///'检查文件扩展名字
            //    HttpPostedFile postedFile = files[iFile];
            //    string fileName, fileExtension;
            //    fileName = System.IO.Path.GetFileName(postedFile.FileName);
            //    if (fileName != "")
            //    {
            //        fileExtension = System.IO.Path.GetExtension(fileName);
            //        //strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>");
            //        //strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>");
            //        //strMsg.Append("上传文件的文件名:" + fileName + "<br>");
            //        //strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr>");
            //        ///'可根据扩展名字的不同保存到不同的文件夹
            //        ///注意:可能要修改你的文件夹的匿名写入权限。
            //        ///
 
            //       // postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("contractImgs/") + Guid.NewGuid().ToString()+ fileName);
 
 
            //    }
            //}
        }
 
        public void  test()
        {
            return;
        }
        
        /// <summary>
        /// 获取当前页面的guiid,判断是否时新建页面
        /// </summary>
        /// <returns></returns>
        public Guid? GetContractFileID()
        {
            Guid Keyid = Request["Keyid"].ToGuid2();
            Database DC = new Database();
            string sqlStr = string.Format(@"USE [ECTEST] SELECT[Keyid] FROM[dbo].[OA_CorporateClientContract] where CorporateClientsid='{0}' and [PageCode]='{1}' ", Keyid, Convert.ToInt32(this.TextPage.Value));
 
            try
            {
                SqlCommand myCmd = new SqlCommand(sqlStr, DC.Connection);
                //SqlDataAdapter myDa = new SqlDataAdapter(myCmd);
                var a = myCmd.ExecuteReader();
                //myDa.Dispose();
               List<OA_CorporateClientsContract> ff = new List<OA_CorporateClientsContract>();
                OA_CorporateClientsContract Contract;
                while (a.Read())
                {   //注意如何将每次读取到的记录添加到listbox1中(因为第一次做时出错了,嘿嘿)
                    Contract = new OA_CorporateClientsContract();
                    Contract.Keyid = a.GetGuid(0);
                    ff.Add(Contract);
                }
                a.Close();     //关闭sqldatareader
                if (ff.Count >= 0)
                    return ff[0].Keyid;
                else return null;
            }
            catch (Exception ee)
            {
                new Log4NetAdapter().Log("查找合同出错:" + ee.Message);
                return null;
            }
            finally
            {
                if (DC.Connection.State != System.Data.ConnectionState.Closed)
                    DC.Connection.Close();
            }
 
        }
 
 
 
    }
}