download ReviseComponent.aspx.cs
Language: C#
Copyright: (C) 2007 Jiing Deng @ CathayBK
LOC: 467
Project Info
common-component-mng-sys - Common Componen...e ...(common-component-mng-sys)
Server: Google
Type: svn
...on‑component‑mng‑sys\trunk\
   AddNewComponent.aspx
   AddNewComponent.aspx.cs
   ADLogin.aspx
   ADLogin.aspx.cs
   ...SearchActionChoice.aspx
   ...rchActionChoice.aspx.cs
   CathayBkRSS.xml
   Comment.aspx
   Comment.aspx.cs
   ...n-component-mng-sys.sln
   ...onent-mng-sys_Model.tgs
   ComponentsList.html
   Default.aspx
   Default.aspx.cs
   Downloading.aspx
   Downloading.aspx.cs
   ErrorPage.htm
   Global.asax
   Logon.aspx
   Logon.aspx.cs
   ManagerMain.aspx
   ManagerMain.aspx.cs
   MasterPage.master
   MasterPage.master.cs
   ReviseComponent.aspx
   ReviseComponent.aspx.cs
   SearchComponent.aspx
   SearchComponent.aspx.cs
   SearchResult.aspx
   SearchResult.aspx.cs
   StatisticsReport.aspx
   StatisticsReport.aspx.cs
   ...oDownloadComponent.aspx
   ...wnloadComponent.aspx.cs
   web.config
   Web.sitemap
   ...ejectReasonAndMail.aspx
   ...ctReasonAndMail.aspx.cs

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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;
using System.Net.Mail;

public partial class ReviseComponent : System.Web.UI.Page
{
    /// <summary>
    /// Copyright (C) 2007 Jiing Deng @ CathayBK
    /// 
    /// </summary>
    private string strFileSavePath =
         System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;

    #region  lɩҰʧ@
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack) 
        {
            fvReviseComponent.ChangeMode(FormViewMode.Edit);    // NFormView ܴEditҦ
           // btnGo2Main.Visible = false;
           // btnUpdate.Visible = true;
            
            // qƮwd߬ơA⥦̨qbEdit ModeWAӵϥΪ̽s
           // showMsg("qƮwd߬ơA⥦̨qbEdit ModeWAӵϥΪ̽s");
            try
            {             
            //    // qƮwoƤAAsثeEdit Mode
            //    // string componentName; ݯणo~Ѽ -- componentNamehd
                string componentID = Request.QueryString["componentID"];   //γoӴե\઺i       
                string[] myDSetOfComponent = queryFromDBbyComponentID(componentID);

                // Label lblTemp = (Label)fvReviseComponent.FindControl("lblContributor");
                // lblTemp.Text = Context.User.Identity.Name;     //put user name on pages
                FormView myFormView = (FormView)Page.FindControl("fvReviseComponent");

                DropDownList myDdlVersion1 = (DropDownList)myFormView.FindControl("ddlVersion1");
                DropDownList myDdlVersion2 = (DropDownList)myFormView.FindControl("ddlVersion2");
                DropDownList myDdlVersion3 = (DropDownList)myFormView.FindControl("ddlVersion3");

                string[] strVersionTmp = myDSetOfComponent[8].Split('.');
                myDdlVersion1.SelectedValue = strVersionTmp[0];
                myDdlVersion2.SelectedValue = strVersionTmp[1];
                myDdlVersion3.SelectedValue = strVersionTmp[2];




                Image myImageDemoScrShot = (Image)myFormView.FindControl("imgDemoScrShot");
                //myDSetOfComponent[8].Trim(); is the old version 

                if (File.Exists(strFileSavePath + "UploadImages/" + componentID + "_" + myDSetOfComponent[8].Trim()))
                {
                    myImageDemoScrShot.ImageUrl = strFileSavePath + "UploadImages/" + componentID + "_" + myDSetOfComponent[8].Trim();
                }else
                {
                   myImageDemoScrShot.ImageUrl=strFileSavePath + "UploadImages/default.png";
                }
            
            }
            catch (Exception ex)
            {
               Response.Write(ex.Message.ToString());

            }
        }
    }
    #endregion 

    #region qƮwŪƥX
    /// <summary>
    /// @SQLROӱqDBd߷QnӸ`C
    /// </summary>    
    /// <param name="componentName">W١Adߦ󪺲Ӹ`</param>
    /// <returns>^Ǥ@DataSet</returns>
    protected string[] queryFromDBbyComponentID(string componentID)
    {
        //}lӭnqƮwŪXJ, sqlOtW٩ΤID

        ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
        string CCSConnectionString = connSettings.ConnectionString;

        string cmdQuery = "SELECT * FROM COMPONENT WHERE COMPONENT_ID = '" + componentID + "' ";

        SqlConnection Conn = new SqlConnection(CCSConnectionString);

        //DataSet dsComponetFields = new DataSet();

        string[] retString = new string[28];


        try
        {
            Conn.Open();
        }
        catch (SqlException ex)
        {
            // Connection failed
            showMsg(ex.Message);
        }

        SqlCommand command = new SqlCommand(cmdQuery, Conn);
        command.CommandType = System.Data.CommandType.Text;
        SqlDataReader rdr = command.ExecuteReader();

        try
        {            
            do
            {             
                while (rdr.Read())
                {
                   for(int ix = 0; ix< rdr.FieldCount - 1; ix++){
                     retString[ix] = rdr.GetValue(ix).ToString();
                   }
                    //retString[ix] = rdr.GetValue(0).ToString();

                    //ix++;
                }
            } while (rdr.NextResult());

        }
        catch (SqlException ex)
        {
            showMsg(ex.Message);
        }
        finally
        {
            Conn.Close();    //remember to close the db connection
            rdr.Close();
            
        }

        return retString;
    }
    #endregion


    #region bק蠟ApG榡XzAUssʧ@
    protected void UpdateButton_Click(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            showMsg("AUFssAUӷ|NƧsܸƮw");
        }
        StringBuilder strBd = new StringBuilder("");
        strBd.AppendFormat("{0:yyyy/MM/dd-HH:mm:ss}", System.DateTime.Now);

        //A@ǭnJ쵹X        
        FormView myFormView         = (FormView)Page.FindControl("fvReviseComponent");
        Label myComponentID         = (Label)myFormView.FindControl("lblComponentID");

        TextBox myTbxName            = (TextBox)myFormView.FindControl("tbxName");
        DropDownList myDdlVersion1   = (DropDownList)myFormView.FindControl("ddlVersion1");
        DropDownList myDdlVersion2   = (DropDownList)myFormView.FindControl("ddlVersion2");
        DropDownList myDdlVersion3   = (DropDownList)myFormView.FindControl("ddlVersion3");
        TextBox myTbxPath            = (TextBox)myFormView.FindControl("tbxPath");
        DropDownList myDdlFramework  = (DropDownList)myFormView.FindControl("ddlFramework");
        TextBox myTbxFrame = (TextBox)myFormView.FindControl("tbxFramework");
        Label myLblContributor       = (Label)myFormView.FindControl("lblContributor");
        DropDownList myDdlType       = (DropDownList)myFormView.FindControl("ddlType");
        TextBox myTbxType = (TextBox)myFormView.FindControl("tbxType");
        TextBox myTbxNote            = (TextBox)myFormView.FindControl("tbxNote");
        TextBox myTbxToDo            = (TextBox)myFormView.FindControl("tbxToDo");
        DropDownList myDdlIDE        = (DropDownList)myFormView.FindControl("ddlIDE");
        TextBox myTbxDescription     = (TextBox)myFormView.FindControl("tbxDescription");
        TextBox myTbxSynposis        = (TextBox)myFormView.FindControl("tbxSynposis");
        DropDownList myDdlTestEnv    = (DropDownList)myFormView.FindControl("ddlTestEnv");
        DropDownList myDdlCopyright  = (DropDownList)myFormView.FindControl("ddlCopyright");
        TextBox myTbxAcknowledgement = (TextBox)myFormView.FindControl("tbxAcknowledgement");
        TextBox myTbxSeeAlso         = (TextBox)myFormView.FindControl("tbxSeeAlso");
        TextBox myTbxAP_ID           = (TextBox)myFormView.FindControl("tbxAP_ID");
        TextBox myTbxAP_Name         = (TextBox)myFormView.FindControl("tbxAP_Name");
        TextBox myTbxEmail           = (TextBox)myFormView.FindControl("tbxEmail");
        TextBox myTbxPhone           = (TextBox)myFormView.FindControl("tbxPhone");

        //next ,we all insert the all available data into database

        ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
        string CCSConnectionString = connSettings.ConnectionString;

        //UPDATE Table1
       //SET Column1 = Value1, Column2 = Value2
      //WHERE Some_Column = Some_Value       
       string componentID = Request.QueryString["componentID"];   //γoӴե\઺i       
       string UpdateCommand =
            "UPDATE COMPONENT SET NAME = " + "'" + myTbxName.Text.Trim() + "'" + ", "
                               + "TYPE = " + "'" + myDdlType.SelectedValue.Trim() + "'" + ", "
                               + "CONTRIBUTOR = " + "'" + myLblContributor.Text.Trim() + "'" + ", "
                               + "FRAMEWORK = " + "'" + myDdlFramework.SelectedValue.Trim() + "'" + ", "
                               + "PATH = " + "'" + myTbxPath.Text.Trim() + "'" + ", "
                               + "VERSION = " + "'" + myDdlVersion1.SelectedValue.Trim() + "." + myDdlVersion2.SelectedValue.Trim() + "." + myDdlVersion3.SelectedValue.Trim() + "'" + ", "
                               + "SYNPOSIS = " + "'" + myTbxSynposis.Text.Trim() + "'" + ", "
                               + "DESCRIPTION = " + "'" + myTbxDescription.Text.Trim() + "'" + ", "
                               + "TEST_ENVIRONMENT = " + "'" + myDdlTestEnv.SelectedValue.Trim() + "'" + ", "
                               + "IDE = " + "'" + myDdlIDE.SelectedValue.Trim() + "'" + ", "
                               + "NOTE = " + "'" + myTbxNote.Text.Trim() + "'" + ", "
                               + "TODO = " + "'" + myTbxToDo.Text.Trim() + "'" + ", "
                               + "SEE_ALSO  = " + "'" + myTbxSeeAlso.Text.Trim() + "'" + ", "
                               + "ACKNOWLEDGEMENT = " + "'" + myTbxAcknowledgement.Text.Trim() + "'" + ", "
                               + "COPYRIGHT = " + "'" + myDdlCopyright.SelectedValue.Trim() + "'" + ", "
                               + "AP_ID = " + "'" + myTbxAP_ID.Text.Trim() + "'" + ", "
                               + "AP_NAME = " + "'" + myTbxAP_Name.Text.Trim() + "'" + ", "
                               + "EMAIL = " + "'" + myTbxEmail.Text.Trim() + "'" + ", "
                               + "PHONE = " + "'" + myTbxPhone.Text.Trim() + "'" + ", "
                               + "IS_VALID1 = " + "'' , "
                               + "IS_VALID2 = " + "'' , "
                               + "MYDATETIME = " + "'" + strBd + "'" + ", "
                               + "STATUS = " + "'R' " 
                               + "WHERE COMPONENT_ID = '" + componentID  +"' " ;                   

     //  showMsg(UpdateCommand);

        SqlConnection Conn = new SqlConnection(CCSConnectionString);

        try
        {
            Conn.Open();
        }
        catch (SqlException ex)
        {
            // Connection failed
            showMsg(ex.Message);
        }

        try
        {
            SqlCommand command = new SqlCommand(UpdateCommand, Conn);
            command.CommandType = System.Data.CommandType.Text;
            command.ExecuteNonQuery();
        }
        catch (SqlException ex)
        {
            showMsg(ex.Message);
        }
        catch (Exception ex) 
        {
            showMsg(ex.Message);
        }
        finally
        {
            Conn.Close();    //remember to close the db connection
    //        generateRSSFeed("ק", componentID);
        }

        string strMyVersionNow = myDdlVersion1.SelectedValue.Trim() + "." + myDdlVersion2.SelectedValue.Trim() + "." + myDdlVersion3.SelectedValue.Trim();
        ImageFileUpload(componentID, strMyVersionNow);

      
        SrcCodeFileUpload(componentID, strMyVersionNow); //WǭlX{




        showMsg("ק粒");

        SendMail2ContributorAboutWaitForAudit(componentID);

        //btnUpdate.Visible = false;
        fvReviseComponent.ChangeMode(FormViewMode.ReadOnly);

       
        //Server.Transfer("~/Default.aspx");


        //ק露󦨥\ɥ[WGrowlĪGH        
    //    FormView myFormView2 = (FormView)Page.FindControl("fvReviseComponent");
    //    fvReviseComponent.ChangeMode(FormViewMode.ReadOnly);    // NFormView ܴRead onlyҦ
    //    fvReviseComponent.DataBind();
//        Server.Transfer("./ReviseComponent.aspx");
   //     myFormView2.DataBind();


    }
    #endregion

    #region vɮפWǨ /UploadImages/
    protected void ImageFileUpload(string strComponentID, string strMyVersionNow)
    {
        FormView myFormView = (FormView)Page.FindControl("fvReviseComponent");
        FileUpload myFileuploadImage = (FileUpload)myFormView.FindControl("fileUploadImage");
        Label myLblUploadImage = (Label)myFormView.FindControl("lblUploadImage");

         Label myLblVersionOld = (Label)myFormView.FindControl("lblVersionOld");


        string fullname = strComponentID + "_" + strMyVersionNow;     //`Nsɪ覡

        string url = myFileuploadImage.PostedFile.FileName.ToString();        //oӬOHe2003ΪAoWǤ|ӦWrAMAQSubStringkӱoΤWA{bݨӬOSnF
        string typ = myFileuploadImage.PostedFile.ContentType.ToString();     //MIMEe
        string typ2 = fullname.Substring(fullname.LastIndexOf(".") + 1);  //Wr . ᭱rŧ@
        string size = myFileuploadImage.PostedFile.ContentLength.ToString();


        bool fileIsOK = false;
        // string path = Server.MapPath("~/");


        if (myFileuploadImage.HasFile)
        {
            string fileExtension = System.IO.Path.GetExtension(myFileuploadImage.FileName).ToLower();
            string[] allowedExtensions ={ ".gif", ".png", ".jpeg", ".jpg" };  //ΪN\F

            for (int i = 0; i < allowedExtensions.Length; i++)
            {
                if (fileExtension == allowedExtensions[i])
                {
                    fileIsOK = true;
                }
            }

            if (fileIsOK)
            {

                try
                {
                    myFileuploadImage.SaveAs(Server.MapPath("~/UploadImages/") + "\\" + fullname);//NOsbؿUP󧨤U
                    myLblUploadImage.Text = ("AWǤF@ӦW" + fullname + "AMIMEe[" + typ + "]AW[" + typ2 + "]A@[" + size + "] bytejp<br>wgOsbFAWǥؿFI");
                }
                catch (Exception ex)
                {
                    myLblUploadImage.Text = ex.Message.ToString();
                }
            }
            else
            {
                myLblUploadImage.Text = "WǮ榡~H";
            }
        }
        else {
            if (File.Exists(Server.MapPath("~/UploadImages/") + "\\" + strComponentID + "_" + myLblVersionOld.Text))
                File.Move(Server.MapPath("~/UploadImages/") + "\\" + strComponentID + "_" + myLblVersionOld.Text,  Server.MapPath("~/UploadImages/") + "\\" + fullname);        
        }


    }
    #endregion

   


    protected void showMsg(string AlertMessage)
    {
        Literal txtMsg = new Literal();
        txtMsg.Text = "<script>alert('" + AlertMessage + "')</script>" + "<br/>";
        Page.Controls.Add(txtMsg);
    }


    protected void fvReviseComponent_ItemUpdated(object sender, FormViewUpdatedEventArgs e)
    {
        fvReviseComponent.ChangeMode(FormViewMode.ReadOnly);    // NFormView ܴReadOnlyҦ

    }

    #region ͦRSS Feed z
    private void generateRSSFeed(string strMsgLevel, string strComponentID)
    {
        SqlConnection conn = null;
        SqlCommand cmd = null;
        SqlDataReader reader = null;
        RSSChannel channel = null;
        StreamWriter sw = null;
        StreamReader sr = null;               
        int a = 0;
        try
        {
            channel = new RSSChannel();

            channel.title = "@ظTBG@Τ޲zt Feed";
            channel.webMaster = "jiing.deng@cathaybk.com.tw";
            channel.managingEditor = "jiing.deng@cathaybk.com.tw";
           // channel.link = "http://www.cathaybk.com.tw";
            channel.description = "@ظTBUx@Τ󤽧i";
            ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
            string CCSConnectionString = connSettings.ConnectionString;


            conn = new SqlConnection(CCSConnectionString);
            cmd = new SqlCommand("SELECT NAME,FRAMEWORK,VERSION,DL_LINK,DESCRIPTION FROM COMPONENT WHERE COMPONENT_ID ='" + strComponentID + "'" + "WITH (NOLOCK) ORDER BY NAME,VERSION DESC",
                                       conn);
             

            conn.Open();
            reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                channel.AppendRSSItem("[" + strMsgLevel + "]" + reader["NAME"].ToString().Trim() + " for " +
                                    reader["FRAMEWORK"].ToString().Trim() + " Ver" +
                                        reader["VERSION"].ToString().Trim(),
                                  //  reader["DL_LINK"].ToString().Trim(),
                                    reader["DESCRIPTION"].ToString().Trim(), string.Empty);
            }
            reader.Close();
            conn.Close();
            string filename = strFileSavePath + "CathayBK.rss";
            bool isAppend = File.Exists(filename);
            if (!isAppend)
            {
                sw = new StreamWriter(filename, false, System.Text.Encoding.GetEncoding("utf-8"));
                sw.WriteLine(channel.GenerateChannel());
            }
            else
            {
                sr = new StreamReader(filename, System.Text.Encoding.GetEncoding("utf-8"));
                string original = sr.ReadToEnd();
                sr.DiscardBufferedData();
                sr.Dispose();


                string newTxt = string.Empty;
                for (a = 0; a < channel.itemLst.Count; a++)
                {
                    newTxt += ((RSSItem)channel.itemLst[a]).GenerateItem();
                }

                //夤Ĥ@Item
                int thePos = original.IndexOf("<item>");
                if (thePos > 0)
                {
                    //NHUeUguidXﻼW
                    int target1 = original.IndexOf("<guid>", thePos);
                    int target2 = 0;
                    while (target1 > thePos)
                    {
                        target2 = original.IndexOf("</guid>", target1 + "<guid>".Length);
                        string match = original.Substring(target1 + "<guid>".Length, target2 - (target1 + "<guid>".Length));
                        int lastSharp = match.LastIndexOf('#');
                        int newNum = int.Parse(match.Substring(lastSharp + "#".Length)) + a;
                        string newMatch = match.Substring(0, lastSharp) + "#" + newNum.ToString().Trim();

                        original = original.Replace("<guid>" + match + "</guid>", "<guid>" + newMatch + "</guid>");

                        target1 = original.IndexOf("<guid>", target2 + "</guid>".Length);
                    }

                    original = original.Insert(thePos, newTxt);
                }

                sw = new StreamWriter(filename, false, System.Text.Encoding.GetEncoding("utf-8"));
                sw.WriteLine(original);
            }
            sw.Flush();
            sw.Close();

            sw.Dispose();
            reader.Dispose();
            cmd.Dispose();
            conn.Dispose();
        }
        catch (Exception exp)
        {
            showMsg(exp.Message);
        }
        finally
        {
            reader = null;
            cmd = null;
            conn = null;
            channel = null;
            sw = null;
            sr = null;
        }
    }
    #endregion

    protected void tbxType_TextChanged(object sender, EventArgs e)
    {
        FormView myFormView = (FormView)Page.FindControl("fvReviseComponent");
        DropDownList myDdlType = (DropDownList)myFormView.FindControl("ddlType");
        TextBox myTbxType = (TextBox)myFormView.FindControl("tbxType");
        
        myDdlType.Enabled = true;
        
    }
    protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
    {
       // FormView myFormView = (FormView)Page.FindControl("fvReviseComponent");
       // DropDownList myDdlType = (DropDownList)myFormView.FindControl("ddlType");
       //// myDdlType.Enabled = true;

       
       // TextBox myTbxType = (TextBox)myFormView.FindControl("tbxType");
       // myTbxType.Text = myDdlType.Text;
    }
    protected void ddlType_TextChanged(object sender, EventArgs e)
    {
        
    }
    protected void btnGo2Main_Click(object sender, EventArgs e)
    {
        Server.Transfer("~/Default.aspx");
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {

    }


    #region {lXWǨ UploadSrcCode
    protected void SrcCodeFileUpload(string strComponentID, string strMyVersionNow)
    {
        FormView myFormView = (FormView)Page.FindControl("fvReviseComponent");
        FileUpload myFileuploadSrcCode = (FileUpload)myFormView.FindControl("fileUploadSrcCode");
        Label myLblUploadSrcCode = (Label)myFormView.FindControl("lblUploadSrcCode");



        string fullname = strComponentID + "_" + strMyVersionNow + "_" + myFileuploadSrcCode.FileName.ToString();    //oW          


        //configSection.MaxRequestLength = 1024*10;  //̤jW10MBAw]ȬO4MB
        string url = myFileuploadSrcCode.PostedFile.FileName.ToString();        //oӬOHe2003ΪAoWǤ|ӦWrAMAQSubStringkӱoΤWA{bݨӬOSnF
        string mimeType = myFileuploadSrcCode.PostedFile.ContentType.ToString();     //MIMEe
        string typ2 = fullname.Substring(fullname.LastIndexOf(".") + 1);  //Wr . ᭱rŧ@
        string size = myFileuploadSrcCode.PostedFile.ContentLength.ToString();


        bool fileIsOK = false;
        // string path = Server.MapPath("~/");


        if (myFileuploadSrcCode.HasFile)
        {
            string fileExtension = System.IO.Path.GetExtension(myFileuploadSrcCode.FileName).ToLower();
            string[] allowedExtensions ={ ".zip", ".rar", ".c", ".cpp", ".txt", ".pl", ".plx", ".cs", ".aspx", ".m", ".asp", ".vb" }; //VCiWǪɮ׮榡

            for (int i = 0; i < allowedExtensions.Length; i++)
            {
                if (fileExtension == allowedExtensions[i])
                {
                    fileIsOK = true;
                }
            }
        }

        if (fileIsOK)
        {

            try
            {
                myFileuploadSrcCode.SaveAs(Server.MapPath("~/UploadSrcCode/") + "\\" + fullname);//NOsbؿUP󧨤U
                myLblUploadSrcCode.Text = ("AWǤF@ӦW" + fullname + "AMIMEe[" + mimeType + "]AW[" + typ2 + "]A@[" + size + "] bytejp<br>wgOsbFAWǥؿFI");
            }
            catch (Exception ex)
            {
                myLblUploadSrcCode.Text = ex.Message;
            }
        }
        else
        {
            myLblUploadSrcCode.Text = "WǮ榡~H";

        }
    }
    #endregion

    #region Heemail󪺶}o̡Ai󥿵ݺ޲z̼f
    private void SendMail2ContributorAboutWaitForAudit(string strComponentID)
    {

        //Step 1. dEmail
        string strEmailAddress = "";
        SqlConnection conn = null;
        SqlCommand cmd = null;
        SqlDataReader reader = null;
        try
        {
            ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
            string CCSConnectionString = connSettings.ConnectionString;

            conn = new SqlConnection(CCSConnectionString);
            cmd = new SqlCommand("SELECT EMAIL FROM COMPONENT WHERE COMPONENT_ID ='" + strComponentID + "'", conn);

            conn.Open();
            reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                strEmailAddress = reader["EMAIL"].ToString().Trim();
            }
        }
        catch (Exception ex)
        {
            showMsg(ex.Message);
        }
        finally
        {
            reader.Close();
            conn.Close();
        }

        //Step 2.HoEmail 󪺶}o    
        sendEMail("", strEmailAddress);

    }

    #endregion


    #region HeEmailiT
    private void sendEMail(string strMailBody, string strMailToAddress)
    {

        //PɱHe޲z̻PϥΪ  
        String strTo = "<jiing.deng@cathaybk.com.tw>;" + strMailToAddress;
        //ӷO@Τ޲ztΩM޲z
        String strFrom = "<CCOM@cathaybk.com.tw>";
        String strMailSubject = "[@Τ]@Τ޲ztΪAqHI";

        if (String.IsNullOrEmpty(strMailBody))
        {
            strMailBody = "oOѦ@Τ޲ztγqT</b>A<b>zҭק諸Aثeݺ޲z̼f<br>";

        }
        System.Net.Mail.SmtpClient client = new SmtpClient();
        client.Host = "PIEX2K05.cathaybk.intra.uwccb";
        client.Port = 25;
        client.UseDefaultCredentials = false;
        client.Credentials = new System.Net.NetworkCredential("uid", "pwd");  //uid, pwd please replace as yours
        client.DeliveryMethod = SmtpDeliveryMethod.Network;

        System.Net.Mail.MailMessage message = new MailMessage(strFrom, strTo, strMailSubject, strMailBody);
        message.BodyEncoding = System.Text.Encoding.UTF8;
        message.IsBodyHtml = true;

        try
        {
            client.Send(message);
            Response.Write("<font color=\"blue\">Email successfully sent.</font>");
        }
        catch (Exception ex)
        {
            Response.Write("Send Email Failed." + ex.ToString()); ;
        }
    }
    #endregion
}

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us