A
download SearchComponent.aspx.cs
Language: C#
LOC: 417
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
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.RegularExpressions;
using System.Collections.Generic;

public partial class SearchComponent : System.Web.UI.Page
{
    private ArrayList menu = new ArrayList();
    string strFunction = String.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) 
        {
            //strFunction = Request.QueryString["functionName"];
            //Response.Write(Request.QueryString["ComponentName"]);  //QueryStringǰѼƪk
            GenTreeNodes("ASP");   //Default loading the ASP TreeView in the initial state
        }
    }

    #region split path and rearrange
    private void splitPathAndRearrange(string strFrameworkType) 
    {
        //wqRoot Node

        TreeNode RootNode = new TreeNode();
        RootNode.Text = "CathayBk " + strFrameworkType +" Tree";
        RootNode.Value = "Common Components Tree";
       // RootNode.NavigateUrl = "~/SearchResult.aspx?pathName=%";   //ܩI露󪺲Ӹ`
        TreeViewOfPath.Nodes.Add(RootNode);

        //ھکҿ諸FrameworkAhƮwd߲Ĥ@h`IWAMjʺAa
        string[] rtnArray = queryParentNodesByFramework(strFrameworkType);   //^ǤF@ʵơAO䤤i঳Ū

        //p@UXD
        int intCountOfItemInRtnArray = 0;        
        foreach (string strItem in rtnArray)
        {
            if (strItem != null) { intCountOfItemInRtnArray++; }        
        }

        //dzưY²Arrayʧ@
        string[] strArrayToParse = new string[intCountOfItemInRtnArray];

        int ix = 0;
        foreach (string strItem in rtnArray)
        {
            if (strItem != null) 
            {
                strArrayToParse[ix] = rtnArray[ix];
                ix++; 
            }
        }

        int ixx = 0;
        string[,] path = new string[strArrayToParse.Length, 3];  //]uThAG3
        foreach (string strItem in strArrayToParse)
        {          
            //wqTh𪬹
            Regex exp = new Regex(
               // @"(\w+|\W+)\:(\w+|\W+)\:(\w+|\W+)\:?(\w+|\W+)?"-
                @"(\w+|\W+)\:(\w+|\W+)\:?(\w+|\W+)?"
              );
         
            MatchCollection MatchList = exp.Matches(strItem);
            Match FirstMatch = MatchList[0];
            //int temp = FirstMatch.Groups.Count
                     
            for (int jx = 1; jx < FirstMatch.Groups.Count; jx++)
            {               
                path[ixx,jx-1] = FirstMatch.Groups[jx].Value;        //|hRXӡApath}C
            }
            ixx++;
       }

        //Dz߰ʺAͦTree
        //1. XҦڸ`I
        string[] strPathRootArray = new string[ixx];
        for(int jx=0 ; jx< ixx ; jx++){
           strPathRootArray[jx]= path[jx,0];        
        }

        //2. Xuniqueڸ`I
                
        ArrayList UniqueList= new ArrayList();
        int jxx = 0;
       
        while ( jxx < strPathRootArray.Length )
        {
            if (!UniqueList.Contains(strPathRootArray[jxx]))   
                UniqueList.Add(strPathRootArray[jxx]);         
            jxx++;
        }
        
        foreach(string strItem in UniqueList){
         //  string strTemp =RootNode.Text+ ":"+ strItem;
          // menu.Add(strTemp);
            menu.Add(strItem);
        }
       
             
         ArrayList uniqueParentNodes= new ArrayList();
        //Xثepath}CA UniqueUӪunique`I
        foreach (string strItem in UniqueList)
        {
            int bx = 0;
            while(bx < strArrayToParse.Length)
            {               
                if (path[bx, 0] == strItem && !uniqueParentNodes.Contains(path[bx, 0] + ":" + path[bx, 1]))   //not contains the string yet
                {
                    uniqueParentNodes.Add(path[bx, 0] + ":" + path[bx, 1]);
                }
                bx++;
            }
        }

        foreach (string strItem in uniqueParentNodes)
        {
            //  string strTemp =RootNode.Text+ ":"+ strItem;
            // menu.Add(strTemp);
            menu.Add(strItem);
        }

        foreach (string strItem in strArrayToParse) 
        {
            if (!uniqueParentNodes.Contains(strItem))
           {
               menu.Add(strItem);
           }
        }

        //quniqueparent nodes^ڸ`I
        
             //TreeViewOfPath.PathSeparator = ':';   //]wPath Separator


            // ھڭRXrApGثeTreeViewSAhhsWδJ`I`IW]Node^
            // ҥHo䪺𪬹ϡA٬On depth = 3 n,Xhثew
       // menu.TrimToSize();
        if (menu.Count > 0)
        {
            SetupMenu();
        }
        else {
            showMsg("SؤALkͦI");
        }
    }
    #endregion 

    #region إTreeView`I
    private void GenTreeNodes(string strFrameworkType) 
    {
             
        TreeViewOfPath.ShowLines = true;
       
        
        splitPathAndRearrange(strFrameworkType); 
    }
    #endregion 

   
   private void SetupMenu()
   {
       try
       {
           menu.Sort();

           //ھڨϥΪ̪vŪ椤iX{
           //Cإߤ@Ӹ`I, NߧYMO_٦lI
           for (int i = 0; i < menu.Count; i++)
           {
               if (menu[i].ToString().Trim().IndexOf(':') < 0)
               {
                   TreeNode theNode = new TreeNode(menu[i].ToString().Trim(),
                                                   menu[i].ToString().Trim());
                   BuildSubTree(ref theNode, i);

                   TreeViewOfPath.Nodes.Add(theNode);
                   theNode = null;
               }
           }
       }
       catch (Exception ex)
       {
           showMsg(ex.Message);
       }
   }

   private void BuildSubTree(ref TreeNode node, int lastPos)
   {
       TreeNode theNode = node;
       string thisMenu = string.Empty;

       try
       {
           for (int i = lastPos + 1; i < menu.Count; i++)
           {
               thisMenu = menu[i].ToString().Trim();
               if (thisMenu.IndexOf(theNode.Value) == 0 &&
                    thisMenu.Length > theNode.Value.Length &&
                    thisMenu.Substring(theNode.Value.Length + 1).IndexOf(':') < 0 &&
                    thisMenu.Substring(theNode.Value.Length)[0] == ':')    //unh@CP_
               //oӬOӲI
               {
                   TreeNode tmp = new TreeNode(thisMenu.Substring(theNode.Value.Length + 1),
                                               thisMenu);
                   theNode.ChildNodes.Add(tmp);
                   BuildSubTree(ref tmp, i);
               }
           }
       }
       catch (Exception ex)
       {
           showMsg(ex.Message);
       }
   }

    private string[] queryParentNodesByFramework(string strFrameworkType)
    {
                
        string CCSConnectionString = ConfigurationManager.ConnectionStrings["CCSConnectionString"].ConnectionString;

        string SelectCommand = "SELECT PATH FROM COMPONENT WHERE FRAMEWORK = '"+ strFrameworkType + "' AND STATUS ='P' ORDER BY PATH";

        showMsg(SelectCommand);

        SqlConnection Conn = new SqlConnection(CCSConnectionString);        

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

        string[] resultArray = new string[1000];  //󦳦h֡A1000
        try
        {

            SqlCommand command = new SqlCommand(SelectCommand, Conn);
            command.CommandType = System.Data.CommandType.Text;            
            SqlDataReader rdr = command.ExecuteReader();
            int ix =0;
          
            try
            {
                do
                { 
                    while (rdr.Read())
                    {
                        for ( System.Int32 iCol = 0; iCol < rdr.FieldCount; iCol ++ )
                       {
                        // System.Web.HttpContext.Current.Response.Write( "Column " + iCol.ToString() + ": " );
                         string strTmp = rdr.GetString(iCol).ToString();                    
                         resultArray[ix] = strTmp;
                         ix++;
                       }
                  
                    }
                } while (rdr.NextResult());

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

 

   
    //protected void btnSearch_Click(object sender, EventArgs e)
    //{

    //    string strSearchWord = tbxComponentInfo.Text + "%";  //
    //    string strQueryCommand = "";
    //    switch (ddlSearchType.SelectedValue)
    //    {
    //        case "Full-Text":             
    //            // oӦanjMAinhSQL SERVER Studio ]w@U
    //            strQueryCommand = "SELECT * FROM COMPONENT WHERE FRAMEWORK ='" + ddlFrameworkType.Text +"'";
    //             executeSQLQueryAndDrawResultTable(strQueryCommand);
    //            break;

    //        case "Component Name":
    //            strQueryCommand = "SELECT * FROM COMPONENT WHERE NAME = '" + strSearchWord + "' AND FRAMEWORK ='" + ddlFrameworkType.Text + "'"; 

    //            // uaƮwd
    //             executeSQLQueryAndDrawResultTable(strQueryCommand);
    //            break;

    //        case "Contributor":

    //             strQueryCommand = "SELECT * FROM COMPONENT WHERE CONTRIBUTOR = '" + strSearchWord + "' AND FRAMEWORK ='" + ddlFrameworkType.Text + "'"; 
    //             executeSQLQueryAndDrawResultTable(strQueryCommand);
    //            break;

    //        case "Framework":
    //            strQueryCommand = "SELECT * FROM COMPONENT WHERE FRAMEWORK = '" + strSearchWord + "' AND FRAMEWORK ='" + ddlFrameworkType.Text + "'"; 
    //             executeSQLQueryAndDrawResultTable(strQueryCommand);

    //            break;

    //        case "Category":
    //            // ӻOAjMpathO_oӦr
    //            strQueryCommand = "SELECT * FROM COMPONENT WHERE PATH = '" + strSearchWord + "' AND FRAMEWORK ='" + ddlFrameworkType.Text + "'"; 
    //            executeSQLQueryAndDrawResultTable(strQueryCommand);
    //            break;
    //    }
    //}


    #region ھqueryrӧ@d߰ʧ@AøsG
    private void executeSQLQueryAndDrawResultTable(string strQueryCommand)
    {        
        string CCSConnectionString = ConfigurationManager.ConnectionStrings["CCSConnectionString"].ConnectionString;
        showMsg(strQueryCommand);

        SqlConnection Conn = new SqlConnection(CCSConnectionString);        

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

        // dߪGHDataSetӱH
        string[] resultArray = new string[10000];  //󦳦h֡A10000
        try
        {
            SqlCommand command = new SqlCommand(strQueryCommand, Conn);
            command.CommandType = System.Data.CommandType.Text;            
            SqlDataReader rdr = command.ExecuteReader();
            int ix = 0;
          
            try
            {
                do
                { 
                    while (rdr.Read())
                    {
                        for ( System.Int32 iCol = 0; iCol < rdr.FieldCount; iCol ++ )
                       {
                        // System.Web.HttpContext.Current.Response.Write( "Column " + iCol.ToString() + ": " );
                         string strTmp = rdr.GetString(iCol).ToString();
                      //   System.Web.HttpContext.Current.Response.Write(strTmp);
                      //   System.Web.HttpContext.Current.Response.Write( "<br>" );
                         resultArray[ix] = strTmp;
                         ix++;
                       }
                  
                    }
                } while (rdr.NextResult());

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

    #region  ھڤUԿӿ۹Framework𪬹
    protected void ddlFrameworkType_SelectedIndexChanged(object sender, EventArgs e)
    {
        // ھڤUԿӿ۹Framework𪬹
        
        switch (ddlFrameworkType.SelectedValue.Trim())
        {
            case "ASP":
                showMsg("ӥͦ " + ddlFrameworkType.SelectedValue.Trim().ToString() + " I");
                TreeViewOfPath.Nodes.Clear();                
                menu = null;
                menu = new ArrayList();                
                GenTreeNodes("ASP");
                TreeViewOfPath.ExpandAll();
                break;
            case "ASP.NET":
                showMsg("ӥͦ " + ddlFrameworkType.SelectedValue.Trim().ToString()+" I");
                TreeViewOfPath.Nodes.Clear();        
                menu = null;
                menu = new ArrayList();                
                GenTreeNodes("ASP.NET");
                TreeViewOfPath.ExpandAll();
                break;
            case "C":
                showMsg("ӥͦ " + ddlFrameworkType.SelectedValue.Trim().ToString() + " I");
                TreeViewOfPath.Nodes.Clear();
                menu = null;
                menu = new ArrayList();     
                GenTreeNodes("C");
                TreeViewOfPath.ExpandAll();
                break;

            case "C#":
                showMsg("ӥͦ " + ddlFrameworkType.SelectedValue.Trim().ToString() + " I");
                TreeViewOfPath.Nodes.Clear();
                menu = null;
                menu = new ArrayList();     
                GenTreeNodes("C#");
                TreeViewOfPath.ExpandAll();
                break;

            case "CPlusPlus":
                showMsg("ӥͦ " + ddlFrameworkType.SelectedValue.Trim().ToString() + " I");
                TreeViewOfPath.Nodes.Clear();
                menu = null;
                menu = new ArrayList();     
                GenTreeNodes("CPlusPlus");
                TreeViewOfPath.ExpandAll();
                break;            

            case "Java":
                showMsg("ӥͦ " + ddlFrameworkType.SelectedValue.Trim().ToString() + " I");
                TreeViewOfPath.Nodes.Clear();
                menu = null;
                menu = new ArrayList();     
                GenTreeNodes("Java");
                TreeViewOfPath.ExpandAll();
                break;

            case "JavaScript":
                showMsg("ӥͦ " + ddlFrameworkType.SelectedValue.Trim().ToString() + " I");
                TreeViewOfPath.Nodes.Clear();
                menu = null;
                menu = new ArrayList();     
                GenTreeNodes("JavaScript");
                TreeViewOfPath.ExpandAll();
                break;

            case "MATLAB":
                showMsg("ӥͦ " + ddlFrameworkType.SelectedValue.Trim().ToString() + " I");
                TreeViewOfPath.Nodes.Clear();
                menu = null;
                menu = new ArrayList();     
                GenTreeNodes("MATLAB");
                TreeViewOfPath.ExpandAll();
                break;

            case "Perl":
                showMsg("ӥͦ " + ddlFrameworkType.SelectedValue.Trim().ToString() + " I");
                TreeViewOfPath.Nodes.Clear();
                menu = null;
                menu = new ArrayList();     
                GenTreeNodes("Perl");
                TreeViewOfPath.ExpandAll();
                break;

            case "PHP":
                showMsg("ӥͦ " + ddlFrameworkType.SelectedValue.Trim().ToString() + " I");
                TreeViewOfPath.Nodes.Clear();
                menu = null;
                menu = new ArrayList();     
                GenTreeNodes("PHP");
                TreeViewOfPath.ExpandAll();
                break;

            case "Python":
                showMsg("ӥͦ " + ddlFrameworkType.SelectedValue.Trim().ToString() + " I");
                TreeViewOfPath.Nodes.Clear();
                menu = null;
                menu = new ArrayList();     
                GenTreeNodes("Python");
                TreeViewOfPath.ExpandAll();
                break;
            case "Ruby":
                showMsg("ӥͦ " + ddlFrameworkType.SelectedValue.Trim().ToString() + " I");
                TreeViewOfPath.Nodes.Clear();
                menu = null;
                menu = new ArrayList();     
                GenTreeNodes("Ruby");
                TreeViewOfPath.ExpandAll();
                break;           
            case "VB":
                showMsg("ӥͦ " + ddlFrameworkType.SelectedValue.Trim().ToString() + " I");
                TreeViewOfPath.Nodes.Clear();
                menu = null;
                menu = new ArrayList();     
                GenTreeNodes("VB");
                TreeViewOfPath.ExpandAll();
                break;

            case "VB.NET":
                showMsg("ӥͦ " + ddlFrameworkType.SelectedValue.Trim().ToString() + " I");
                TreeViewOfPath.Nodes.Clear();
                menu = null;
                menu = new ArrayList();     
                GenTreeNodes("VB.NET");
                TreeViewOfPath.ExpandAll();
                break;
        }

      //  SiteMapDSFrameworkType.DataBind();
    }
    #endregion


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

 
    //protected void ddlComponentInfoChanged(object sender, EventArgs e)
    //{
    //    switch (ddlSearchType.SelectedValue.Trim())
    //    {
    //        case "Name":
    //            gvComponentDetails.DataSource = SqlDSComponentNameQuery;
    //            gvComponentDetails.DataBind();
    //            break;
    //        case "Contributor":
    //            gvComponentDetails.DataSource = SqlDSContributorQuery;
    //            gvComponentDetails.DataBind();
    //            break;            
    //        case "Path":
    //            gvComponentDetails.DataSource = SqlDSPathQuery;
    //            gvComponentDetails.DataBind();
    //            break;
    //        case "Full-Text":
    //            gvComponentDetails.DataSource = SqlDSFullTextQuery;
    //            gvComponentDetails.DataBind();
    //            break;
    //    }
    //}
    protected void TreeViewOfPath_SelectedNodeChanged(object sender, EventArgs e)
    {       
           Server.Transfer("~/SearchResult.aspx?pathName=" + TreeViewOfPath.SelectedNode.Text);               
    }
 
    protected void gvComponentDetails_SelectedIndexChanged(object sender, EventArgs e)
    {
          Server.Transfer("~/SearchResult.aspx?pathName=" + gvComponentDetails.SelectedDataKey.Value);                   
    }
    protected void btnFilter_Click(object sender, EventArgs e)
    {
        if (String.IsNullOrEmpty(tbxComponentName.Text))
        {
            tbxComponentName.Text = "%";
        }

        if (String.IsNullOrEmpty(tbxPath .Text))
        {
            tbxPath.Text = "%";
        }
        if (String.IsNullOrEmpty(tbxContributor.Text))
        {
            tbxContributor.Text = "%";
        }
    }
}

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